locking

package module
Version: v0.0.0-...-40133b8 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package locking contains file- and network (port) locking primitives

Index

Constants

This section is empty.

Variables

View Source
var AlreadyLocked = errors.New("AlreadyLocked")

AlreadyLocked is an error

Functions

This section is empty.

Types

type DirLock

type DirLock string

DirLock is a directory lock

func NewDirLock

func NewDirLock(path string) (DirLock, error)

NewDirLock create new directory-based lock (creates a subdir, if not exists, but unlocked first) WARNING: no automatic Unlock on exit/panic!

func (DirLock) Lock

func (lock DirLock) Lock() error

Lock locks (creates .lock subdir)

func (DirLock) TryLock

func (lock DirLock) TryLock() (bool, error)

TryLock acquires the lock, non-blocking

func (DirLock) Unlock

func (lock DirLock) Unlock() error

Unlock releases the directory lock

type FLock

type FLock struct {
	sync.Mutex
	// contains filtered or unexported fields
}

FLock is a file-based lock

func NewFLock

func NewFLock(path string) (*FLock, error)

NewFLock creates new Flock-based lock (unlocked first)

func (*FLock) Lock

func (lock *FLock) Lock() error

Lock acquires the lock, blocking

func (FLock) TryLock

func (lock FLock) TryLock() (bool, error)

TryLock acquires the lock, non-blocking

func (*FLock) Unlock

func (lock *FLock) Unlock() error

Unlock releases the lock

type FLocks

type FLocks []*FLock

FLocks is an array of FLocks, Unlockable at once

func FLockDirs

func FLockDirs(dirs ...string) (FLocks, error)

FLockDirs returns FLocks for each directory

func (FLocks) Unlock

func (locks FLocks) Unlock()

Unlock all locks

type PortLock

type PortLock struct {
	// contains filtered or unexported fields
}

PortLock is a locker which locks by binding to a port on the loopback IPv4 interface

func NewPortLock

func NewPortLock(port int) *PortLock

NewPortLock returns a lock for port

func (*PortLock) Lock

func (p *PortLock) Lock() error

Lock locks on port

func (*PortLock) TryLock

func (p *PortLock) TryLock() (bool, error)

TryLock acquires the lock, non-blocking

func (*PortLock) Unlock

func (p *PortLock) Unlock() error

Unlock unlocks the port lock

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL