Simple TypeScript mutex implementation
npm install @jagi/mutex -Sor
yarn add @jagi/muteximport Mutex from "@jagi/mutex";
const mutext = new Mutex();
const asyncActionResult = await mutex.run(async () => {
// Running asynchronous action.
return await asyncAction();
});
mutex.run(async () => {
// This action will wait for the first one to finish.
await anotherAsyncAction();
});