mirror of
https://github.com/go-micro/go-micro.git
synced 2025-05-31 21:59:42 +02:00
Add Wait option support for sync/etcd plugins (#2459)
* Add Wait support for sync/etcd plugins * Use ErrLockTimeout if context deadline exceeded
This commit is contained in:
parent
c6d352c832
commit
73eda3346d
@ -115,7 +115,15 @@ func (e *etcdSync) Lock(id string, opts ...sync.LockOption) error {
|
||||
|
||||
m := cc.NewMutex(s, path)
|
||||
|
||||
if err := m.Lock(context.TODO()); err != nil {
|
||||
lockCtx := context.Background()
|
||||
if options.Wait > 0 {
|
||||
var cancel context.CancelFunc
|
||||
lockCtx, cancel = context.WithTimeout(lockCtx, options.Wait)
|
||||
defer cancel()
|
||||
}
|
||||
if err := m.Lock(lockCtx); err != nil && err == context.DeadlineExceeded {
|
||||
return sync.ErrLockTimeout
|
||||
} else if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user