promis-reentrant-lock
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

ReentrantLock

Lock mechanism for promises, using a linked list like implementation.

This module is intended to lock promises, forcing some code block to be executed complete before while other contexts wait for the lock to be released.

The module has been written without using arrays using a linked function chain.

It allows 2 semantics:

  • Passing an async callback to the lock method
const promiseLock = new ReentrantLock();
async function () {
    ...
    await promiseLock.lock(async ()=>{
        // your code block
    });   
    ...
}
  • Adquire the lock (you need to release it always)
const promiseLock = new ReentrantLock();
async function () {
    ...
    const releaseLockFn = await promiseLock.acquire();
    try{
        // your code block
    } finally {
        releaseLockFn();
    }
    ...
}

Dependencies (0)

    Dev Dependencies (5)

    Package Sidebar

    Install

    npm i promis-reentrant-lock

    Weekly Downloads

    5

    Version

    1.0.2

    License

    MIT

    Unpacked Size

    3.16 kB

    Total Files

    4

    Last publish

    Collaborators

    • bsjung