MCPcopy
hub / github.com/hwholiday/learning_tools / Lock

Method Lock

etcd/lock/etcd_lock.go:46–63  ·  view source on GitHub ↗

Lock 加锁 等待到超时时间

()

Source from the content-addressed store, hash-verified

44
45// Lock 加锁 等待到超时时间
46func (lock *EtcdLock) Lock() error {
47 lock.ctx, lock.cancel = context.WithTimeout(context.Background(), time.Duration(lock.timeout)*time.Second)
48 response, err := lock.client.Grant(lock.ctx, lock.timeout)
49 if err != nil {
50 return err
51 }
52 lock.session, err = concurrency.NewSession(lock.client,
53 concurrency.WithLease(response.ID),
54 concurrency.WithContext(lock.ctx))
55 if err != nil {
56 return err
57 }
58 lock.mutex = concurrency.NewMutex(lock.session, lock.key)
59 if err = lock.mutex.Lock(lock.ctx); err != nil {
60 return err
61 }
62 return nil
63}
64
65func (lock *EtcdLock) UnLock() error {
66 _ = lock.session.Close()

Callers 15

matchMethod · 0.80
closeMethod · 0.80
InitFunction · 0.80
InitFunction · 0.80
InitFunction · 0.80
log.goFile · 0.80
initLoggerFunction · 0.80
InitFunction · 0.80
PickMethod · 0.80
GetIdMethod · 0.80
GetIdMethod · 0.80
log.goFile · 0.80

Calls

no outgoing calls

Tested by 1

LockFunction · 0.64