sync

package
v5.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 3, 2022 License: Apache-2.0 Imports: 5 Imported by: 4

Documentation

Overview

Package sync is an interface for distributed synchronization

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrLockTimeout = errors.New("lock timeout")
)

Functions

This section is empty.

Types

type Leader

type Leader interface {
	// resign leadership
	Resign() error
	// status returns when leadership is lost
	Status() chan bool
}

Leader provides leadership election.

type LeaderOption

type LeaderOption func(o *LeaderOptions)

type LeaderOptions

type LeaderOptions struct{}

type LockOption

type LockOption func(o *LockOptions)

func LockTTL

func LockTTL(t time.Duration) LockOption

LockTTL sets the lock ttl.

func LockWait

func LockWait(t time.Duration) LockOption

LockWait sets the wait time.

type LockOptions

type LockOptions struct {
	TTL  time.Duration
	Wait time.Duration
}

type Option

type Option func(o *Options)

func Nodes

func Nodes(a ...string) Option

Nodes sets the addresses to use.

func Prefix

func Prefix(p string) Option

Prefix sets a prefix to any lock ids used.

func WithContext

func WithContext(c context.Context) Option

WithContext sets the syncs context, for any extra configuration.

func WithLogger

func WithLogger(l logger.Logger) Option

WithLogger sets the underline logger.

func WithTLS

func WithTLS(t *tls.Config) Option

WithTLS sets the TLS config.

type Options

type Options struct {
	Nodes     []string
	Prefix    string
	TLSConfig *tls.Config
	Context   context.Context
	Logger    logger.Logger
}

type Sync

type Sync interface {
	// Initialize 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
}

Sync is an interface for distributed synchronization.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL