flock

package
v0.0.0-...-389618b Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FLock

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

FLock a type that supports file locking to coordinate work between processes

func New

func New(filePath string) *FLock

New instantiates *FLock on the given path. The path must point to a file not a directory. The file doesn't have to exist prior to calling this method. It will be creating on the first call to TryLock method.

func (*FLock) Lock

func (f *FLock) Lock(ctx context.Context) error

ock tries to acquire an exclusive lock on a file until it succeeds, an error is returned or the context is done.

The callers MUST call the corresponding Unlock method to release the lock and associated resources except when an error is returned (including the context being done).

This method is safe for concurrent access.

Note the given context shouldn't last less than 1 second to be able to acquire the lock.

func (*FLock) TryLock

func (f *FLock) TryLock(timeout time.Duration) error

TryLock tries to acquire an exclusive lock on a file until it succeeds, an error is returned or the timeout is reached.

The callers MUST call the corresponding Unlock method to release the lock and associated resources except when an error is returned (including the timeout).

This method is safe for concurrent access.

Note the given timeout shouldn't be less than 1 second.

func (*FLock) Unlock

func (f *FLock) Unlock() error

Unlock releases the lock and associated resources.

Jump to

Keyboard shortcuts

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