Mutex
A mutual-exclusion lock for async functions: only one holder at a time, waiters served first in first out.
Import:
import { Mutex } from '@mnaoumov/typescript-lib/mutex';Example:
const mutex = new Mutex();
await mutex.runExclusive(async () => { await app.vault.process(file, (content) => content + '\n');});Signature:
export class MutexMethods
| Method | Returns | Description |
|---|---|---|
| acquire(abortSignal?) | Promise<void> | Takes the lock, waiting until it is free. |
| release() | void | Frees the lock, handing it to the longest-waiting caller if there is one. |
| runExclusive(operation, abortSignal?) | Promise<T> | Runs a function while holding the lock, freeing it when the function settles. |
| tryAcquire() | boolean | Takes the lock only if it is free right now. |