Git Product home page Git Product logo

fslock's Introduction

fslock GoDoc

fslock provides a cross-process mutex based on file locks that works on windows and *nix platforms.

fslock

image: public domain (don't ask)

fslock relies on LockFileEx on Windows and flock on *nix systems. The timeout feature uses overlapped IO on Windows, but on *nix platforms, timing out requires the use of a goroutine that will run until the lock is acquired, regardless of timeout. If you need to avoid this use of goroutines, poll TryLock in a loop.

Variables

var ErrLocked error = trylockError("fslock is already locked")

ErrLocked indicates TryLock failed because the lock was already locked.

var ErrTimeout error = timeoutError("lock timeout exceeded")

ErrTimeout indicates that the lock attempt timed out.

type Lock

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

Lock implements cross-process locks using syscalls.

func New

func New(filename string) *Lock

New returns a new lock around the given file.

func (*Lock) Lock

func (l *Lock) Lock() error

Lock locks the lock. This call will block until the lock is available.

func (*Lock) LockWithTimeout

func (l *Lock) LockWithTimeout(timeout time.Duration) error

LockWithTimeout tries to lock the lock until the timeout expires. If the timeout expires, this method will return ErrTimeout.

func (*Lock) TryLock

func (l *Lock) TryLock() error

TryLock attempts to lock the lock. This method will return ErrLocked immediately if the lock cannot be acquired.

func (*Lock) Unlock

func (l *Lock) Unlock() error

Unlock unlocks the lock.

fslock's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.