Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript. Learn more »

await-lock

1.1.3 • Public • Published

AwaitLock Build Status

Mutex locks for async functions and delegating generator functions

npm package

Usage

let lock = new AwaitLock();
 
async function runSerialTaskAsync() {
  await lock.acquireAsync();
  try {
    // Run async code in the critical section
  } finally {
    lock.release();
  }
}

You can also use AwaitLock with co and generator functions.

let runSerialTaskAsync = co.wrap(function*() {
  yield 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();
  }
});

install

npm i await-lock

Downloadsweekly downloads

1,370

version

1.1.3

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability