2020-04-11 12:48:32 +03:00
|
|
|
// Package sync is an interface for distributed synchronization
|
2019-05-31 02:43:23 +03:00
|
|
|
package sync
|
|
|
|
|
|
|
|
import (
|
2020-04-11 12:37:54 +03:00
|
|
|
"errors"
|
2019-05-31 02:43:23 +03:00
|
|
|
)
|
|
|
|
|
2021-04-27 08:32:47 +03:00
|
|
|
// ErrLockTimeout error
|
|
|
|
var ErrLockTimeout = errors.New("lock timeout")
|
2020-04-11 12:37:54 +03:00
|
|
|
|
2020-04-11 12:48:32 +03:00
|
|
|
// Sync is an interface for distributed synchronization
|
2020-04-11 12:37:54 +03:00
|
|
|
type Sync interface {
|
|
|
|
// Initialise options
|
|
|
|
Init(...Option) error
|
|
|
|
// Return the options
|
|
|
|
Options() Options
|
|
|
|
// Elect a leader
|
|
|
|
Leader(id string, opts ...LeaderOption) (Leader, error)
|
|
|
|
// Lock acquires a lock
|
|
|
|
Lock(id string, opts ...LockOption) error
|
|
|
|
// Unlock releases a lock
|
|
|
|
Unlock(id string) error
|
|
|
|
// Sync implementation
|
|
|
|
String() string
|
2019-05-31 02:43:23 +03:00
|
|
|
}
|
|
|
|
|
2020-04-11 12:37:54 +03:00
|
|
|
// Leader provides leadership election
|
|
|
|
type Leader interface {
|
2020-04-12 13:16:08 +03:00
|
|
|
// resign leadership
|
|
|
|
Resign() error
|
|
|
|
// status returns when leadership is lost
|
|
|
|
Status() chan bool
|
2019-05-31 02:43:23 +03:00
|
|
|
}
|