lock

package
v1.0.0-beta.18 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2019 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	LocksDir       string
	Locks          map[string]LockObject
	DefaultTimeout = 24 * time.Hour
)

Functions

func Init

func Init() error

func Lock

func Lock(name string, opts LockOptions) error

func TryLock

func TryLock(name string, opts TryLockOptions) (bool, error)

func Unlock

func Unlock(name string) error

func WithLock

func WithLock(name string, opts LockOptions, f func() error) error

Types

type Base

type Base struct {
	Name        string
	ActiveLocks int
}

func (*Base) GetName

func (lock *Base) GetName() string

func (*Base) Lock

func (lock *Base) Lock(l locker) error

func (*Base) Unlock

func (lock *Base) Unlock(l locker) error

func (*Base) WithLock

func (lock *Base) WithLock(locker locker, f func() error) error

type File

type File struct {
	Base
	LocksDir string
	// contains filtered or unexported fields
}

func (*File) Lock

func (lock *File) Lock(timeout time.Duration, readOnly bool, onWait func(doWait func() error) error) error

func (*File) Unlock

func (lock *File) Unlock() error

func (*File) WithLock

func (lock *File) WithLock(timeout time.Duration, readOnly bool, onWait func(doWait func() error) error, f func() error) error

type LockObject

type LockObject interface {
	GetName() string
	Lock(timeout time.Duration, readOnly bool, onWait func(doWait func() error) error) error
	Unlock() error
	WithLock(timeout time.Duration, readOnly bool, onWait func(doWait func() error) error, f func() error) error
}

func NewFileLock

func NewFileLock(name string, locksDir string) LockObject

type LockOptions

type LockOptions struct {
	Timeout  time.Duration
	ReadOnly bool
}

type TryLockOptions

type TryLockOptions struct {
	ReadOnly bool
}

Jump to

Keyboard shortcuts

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