Skip to content

tkrotoff/await-lock

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AwaitLock Build Status

Mutex locks for async functions and delegating generator functions

npm package

Usage

const lock = new AwaitLock();

async function runSerialTaskAsync() {
  await lock.acquire();
  try {
    // Run async code in the critical section
  } finally {
    lock.release();
  }
}

You can also use AwaitLock with co and generator functions.

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

About

Mutex locks for ES2017 async functions and delegating generator functions

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 90.6%
  • JavaScript 9.4%