@bumblehead/promisemutex

promises added to the mutex are handled sequentially

Usage no npm install needed!

<script type="module">
  import bumbleheadPromisemutex from 'https://cdn.skypack.dev/@bumblehead/promisemutex';
</script>

README

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.