0.0.1 • Published 3 years ago

@bumblehead/promisemutex v0.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
3 years ago

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.