lock

package
v1.0.0-alpha Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2018 License: Apache-2.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 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
}

Jump to

Keyboard shortcuts

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