github.com/annwntech/go-micro/v2@v2.9.5/sync/sync.go (about) 1 // Package sync is an interface for distributed synchronization 2 package sync 3 4 import ( 5 "errors" 6 "time" 7 ) 8 9 var ( 10 ErrLockTimeout = errors.New("lock timeout") 11 ) 12 13 // Sync is an interface for distributed synchronization 14 type Sync interface { 15 // Initialise options 16 Init(...Option) error 17 // Return the options 18 Options() Options 19 // Elect a leader 20 Leader(id string, opts ...LeaderOption) (Leader, error) 21 // Lock acquires a lock 22 Lock(id string, opts ...LockOption) error 23 // Unlock releases a lock 24 Unlock(id string) error 25 // Sync implementation 26 String() string 27 } 28 29 // Leader provides leadership election 30 type Leader interface { 31 // resign leadership 32 Resign() error 33 // status returns when leadership is lost 34 Status() chan bool 35 } 36 37 type Options struct { 38 Nodes []string 39 Prefix string 40 } 41 42 type Option func(o *Options) 43 44 type LeaderOptions struct{} 45 46 type LeaderOption func(o *LeaderOptions) 47 48 type LockOptions struct { 49 TTL time.Duration 50 Wait time.Duration 51 } 52 53 type LockOption func(o *LockOptions)