lock

package
v1.1.14 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrDuplicatedName       utils.Error = "duplicated lock name"
	ErrUnsupportedLockType  utils.Error = "unsupported lock type"
	ErrReentrantKeyNotFound utils.Error = "reentrant key for lock not found"
	ErrTimeout              utils.Error = "try to lock timeout"
	ErrContextDone          utils.Error = "try to lock when context done"
)

Variables

This section is empty.

Functions

func AppName

func AppName(name string) utils.OptionFunc[useOption]

func Construct

func Construct(ctx context.Context, confs map[string]*Conf, opts ...utils.OptionExtender) func()

func Expire

func Expire(expired time.Duration) utils.OptionFunc[lockOption]

func ReentrantKey

func ReentrantKey(key string) utils.OptionFunc[lockOption]

func Within

func Within(ctx context.Context, locker Lockable, key string,
	expired, timeout time.Duration, cb func() error, opts ...utils.OptionExtender) (err error)

Types

type Conf

type Conf struct {
	Type     lockType `yaml:"type" json:"type" toml:"type"`
	Instance string   `yaml:"instance" json:"instance" toml:"instance"`
	Scheme   string   `yaml:"scheme" json:"scheme" toml:"scheme"`
}

Conf lock configure

type Lockable

type Lockable interface {
	Lock(ctx context.Context, key string, opts ...utils.OptionExtender) (err error)
	Unlock(ctx context.Context, key string, opts ...utils.OptionExtender) (err error)
}

func Use

func Use(name string, opts ...utils.OptionExtender) Lockable

type ReentrantLockable

type ReentrantLockable interface {
	Lockable
	ReentrantLock(ctx context.Context, key, reentrantKey string, opts ...utils.OptionExtender) (err error)
}

func UseReentrant

func UseReentrant(ctx context.Context, name string, opts ...utils.OptionExtender) ReentrantLockable

Jump to

Keyboard shortcuts

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