mirror of https://github.com/docker/docs.git
store: Add a channel to lock that is closed if our lock is lost or an error.
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
parent
250a17e954
commit
23481131c4
|
|
@ -257,10 +257,9 @@ func (s *Consul) CreateLock(key string, value []byte) (Locker, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lock attempts to acquire the lock and blocks while doing so.
|
// Lock attempts to acquire the lock and blocks while doing so.
|
||||||
func (l *consulLock) Lock() error {
|
// Returns a channel that is closed if our lock is lost or an error.
|
||||||
// FIXME: Locks may be lost and we should watch for the returned channel.
|
func (l *consulLock) Lock() (<-chan struct{}, error) {
|
||||||
_, err := l.lock.Lock(nil)
|
return l.lock.Lock(nil)
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unlock released the lock. It is an error to call this
|
// Unlock released the lock. It is an error to call this
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ type KVEntry interface {
|
||||||
// Locker provides locking mechanism on top of the store.
|
// Locker provides locking mechanism on top of the store.
|
||||||
// Similar to `sync.Lock` except it may return errors.
|
// Similar to `sync.Lock` except it may return errors.
|
||||||
type Locker interface {
|
type Locker interface {
|
||||||
Lock() error
|
Lock() (<-chan struct{}, error)
|
||||||
Unlock() error
|
Unlock() error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -212,8 +212,12 @@ func (s *Zookeeper) CreateLock(key string, value []byte) (Locker, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lock attempts to acquire the lock and blocks while doing so.
|
// Lock attempts to acquire the lock and blocks while doing so.
|
||||||
func (l *zookeeperLock) Lock() error {
|
// Returns a channel that is closed if our lock is lost or an error.
|
||||||
return l.lock.Lock()
|
func (l *zookeeperLock) Lock() (<-chan struct{}, error) {
|
||||||
|
if err := l.lock.Lock(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return make(<-chan struct{}), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unlock released the lock. It is an error to call this
|
// Unlock released the lock. It is an error to call this
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue