Skip to content

Repository files navigation

@lucid-softworks/mutex

A fair, promise-based mutex for protecting asynchronous critical sections.

import { Mutex } from "@lucid-softworks/mutex";

const mutex = new Mutex();
let sharedValue = 0;

await mutex.runExclusive(async () => {
  sharedValue += 1;
});

Queued callers enter in FIFO order. The mutex is non-reentrant: attempting to acquire it again before releasing it will wait like any other acquisition.

For custom cleanup, call acquire() and invoke the returned idempotent release function in a finally block. The locked and pending getters expose current state.

About

A fair, promise-based asynchronous mutex.

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages