createMutex
Creates a mutex: a lock allowing at most one holder at a time, queueing excess acquire()
callers in FIFO order. A createSemaphore with a single permit.
A factory function rather than a class, matching this package’s other stateful helpers
(debounce, throttle): the returned object closes over an internal semaphore.
Typical use: deduplicating concurrent callers of a non-reentrant operation, e.g. making sure only one in-flight token-refresh call happens at a time while others wait for it.
Available since v3.0.4
Import
Section titled “Import”Signature
Section titled “Signature”Returns
Section titled “Returns”Mutex — A Mutex
Examples
Section titled “Examples”Deduplicate concurrent token refreshes
Section titled “Deduplicate concurrent token refreshes”Only one caller actually refreshes; the rest wait and reuse its result.
isLocked() reports whether the lock is currently held
Section titled “isLocked() reports whether the lock is currently held”Useful for diagnostics or conditionally skipping work while locked.
Related Types
Section titled “Related Types”A mutex created by createMutex.
