Mutex es-toolkit
Ensures that multiple asynchronous tasks do not execute simultaneously.
Usage
Mutex()
Use Mutex when you want to prevent multiple asynchronous tasks from running concurrently. It's useful in situations where you need to control concurrency, such as database connections, file system access, or API call rate limiting.
Properties
isLocked(boolean): Whether the mutex is currently in use. Iftrue, it means there's already an asynchronous task running.
Methods
acquire(() => Promise<void>): Acquires permission to execute an asynchronous task, or waits until permission is granted.release(() => void): Allows the next waiting task to execute.
Source: es-toolkit
Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.