UNPKG

es-toolkit

Version:

A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.

17 lines (14 loc) 314 B
import { Semaphore } from './semaphore.mjs'; class Mutex { semaphore = new Semaphore(1); get isLocked() { return this.semaphore.available === 0; } async acquire() { return this.semaphore.acquire(); } release() { this.semaphore.release(); } } export { Mutex };