A mutex implementation for Deno that supports async/await.
- Simple and lightweight.
- Controls access to code that should run synchronously.
For Deno:
$ deno add @117/mutex
import { createMutex } from "@117/mutex";
const mutex = createMutex();
const work = async () => {
await mutex.acquire();
try {
console.log("mutex acquired, doing work");
} finally {
mutex.release();
}
};
// they will not run concurrently
await Promise.all([work(), work()]);
Feel free to contribute and PR to your 💖's content.