Options
All
  • Public
  • Public/Protected
  • All
Menu

Module @lauf/lock

Lightweight Lock for Mutual Exclusion

codecov

Logo - Image of Runner

Lauf Lock

Logo - Diego Naive, Noun Project.

Install

npm install @lauf/lock --save

@lauf/lock is an implementation of Mutual Exclusion or Mutex. It is incredibly lightweight with no dependencies and is suitable for adoption server-side or client-side in Typescript or Javascript.

To get a lock on a particular key, call lock.acquire(key). The Promise returned will block until every prior requester for that key has already acquired and released their lock, meaning it's your turn. The promise will then resolve to your very own Release function, indicating you have the lock. Finally, call the Release function to notify you have given up the lock.

Browse the API.

Index

Interfaces

Type aliases

Functions

Type aliases

Release

Release: () => void

Type declaration

    • (): void
    • A Release function issued to a caller when they acquire a Lock on a particular key. The caller is expected to invoke this function to give up the lock and allow other processes to enter the mutual exclusion for that key.

      Returns void

Functions

createLock

  • createLock<Key>(): DefaultLock<Key>
  • Create a Lock to assert mutual exclusion for values of type Key

    Type parameters

    • Key = any

    Returns DefaultLock<Key>

Generated using TypeDoc