sync

package
v3.7.3 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

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")

ErrLockTimeout error

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)

LeaderOption func signature

type LeaderOptions

type LeaderOptions struct{}

LeaderOptions holds the leader options

type LockOption

type LockOption func(o *LockOptions)

LockOption func signature

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
}

LockOptions holds the lock options

type Option

type Option func(o *Options)

Option func signature

func Logger

func Logger(l logger.Logger) Option

Logger sets the logger

func Meter added in v3.1.6

func Meter(m meter.Meter) Option

Meter sets the logger

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 Tracer added in v3.1.6

func Tracer(t tracer.Tracer) Option

Tracer sets the tracer

type Options

type Options struct {
	// Logger used for logging
	Logger logger.Logger
	// Tracer used for tracing
	Tracer tracer.Tracer
	// Meter used for merics
	Meter meter.Meter
	// Prefix holds prefix?
	Prefix string
	// Nodes holds the nodes
	// TODO: change to Addrs ?
	Nodes []string
}

Options holds the sync options

func NewOptions added in v3.1.6

func NewOptions(opts ...Option) Options

NewOptions returns options that filled by opts

type Sync

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
}

Sync is an interface for distributed synchronization

func NewSync added in v3.2.10

func NewSync(opts ...Option) Sync

NewSync return new memory sync

Jump to

Keyboard shortcuts

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