UNPKG

@newdash/newdash

Version:

javascript/typescript utility library

36 lines (35 loc) 876 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Mutex = void 0; const Semaphore_1 = require("./Semaphore"); /** * Mutex, the mutex implementation for async operations */ class Mutex extends Semaphore_1.Semaphore { /** * Mutex, the mutex implementation for async operations * * @since 5.15.0 * @category Functional * @example * * ```ts * const mut = new Mutex() * * async call_api(payload: any) { * const release = await mut.acquire() * try { * // ... * // this block, will be executed exclusively * } finally { * release() // release the mutex * } * } * * ``` * */ constructor(defaultAcquireTimeout = -1) { super(1, defaultAcquireTimeout); } } exports.Mutex = Mutex; exports.default = Mutex;