Skip to content

iambumblehead/promisemutex

Repository files navigation

promisemutex

(c)Bumblehead

Build Status

Promises added to the mutex are handled sequentially.

import promisemutex from 'promisemutex';

const mutex = promisemutex();

await Promise.all([
  mutex(async () => {
    await resolveAfterSeconds(4);
    state.firstPromiseEnded = Date.now();
  }),
  mutex(async () => {
    state.secondPromiseStarted = Date.now() + 1;
    await resolveAfterSeconds(1);
  })
]);

In the example, the second async function is called only after the first async function completes. This is useful in rare cases where async functions must be processed sequentially within concurrent stacks.

About

promises added to the mutex are executed sequentially

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published