Wondering what’s next for npm?Check out our public roadmap! »

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

    2.1.0 • Public • Published

    AwaitLock tests codecov

    Mutex locks for async functions

    npm package

    Usage

    import AwaitLock from 'await-lock';
     
    let lock = new AwaitLock();
     
    async function runSerialTaskAsync() {
      await lock.acquireAsync();
      try {
        // IMPORTANT: Do not return a promise from here because the finally clause
        // may run before the promise settles, and the catch clause will not run if
        // the promise is rejected
      } finally {
        lock.release();
      }
    }

    You can also use AwaitLock with co and generator functions.

    import AwaitLock from 'await-lock';
     
    let runSerialTaskAsync = co.wrap(function*() {
      yield lock.acquireAsync();
      try {
        // Run async code in the critical section
      } finally {
        lock.release();
      }
    });

    Install

    npm i await-lock

    DownloadsWeekly Downloads

    20,600

    Version

    2.1.0

    License

    MIT

    Unpacked Size

    12.3 kB

    Total Files

    9

    Last publish

    Collaborators

    • avatar