expo/await-lock

Mutex locks for async functions

TypeScript

96

96 commits

updated Sep 14, 2026

See the code

README

AwaitLock tests codecov

Mutex locks for async functions

API

API documentation

Usage

This package is published only as an ES module. In addition to importing ES modules from ES modules, modern versions of Node.js support requiring ES modules from CommonJS modules.

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();
  }
});
async-await
concurrency
mutex-lock

expo/await-lock

Mutex locks for async functions

TypeScript

96

96 commits

updated Sep 14, 2026

See the code

README

AwaitLock tests codecov

Mutex locks for async functions

API

API documentation

Usage

This package is published only as an ES module. In addition to importing ES modules from ES modules, modern versions of Node.js support requiring ES modules from CommonJS modules.

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();
  }
});
async-await
concurrency
mutex-lock

Significant stargazers

Piepmatz

39 followers · starred Feb 2022