OptionalPromiseOptionaldomainMake a lock reentrant in the same domain.
false
import AsyncLock = require('async-lock');
import * as domain from 'domain';
const lock = new AsyncLock({ domainReentrant: true });
const d = domain.create();
d.run(() => {
lock.acquire('key', () => {
// Enter lock
return lock.acquire('key', () => {
// Enter same lock twice
});
});
});
OptionalmaxMax amount of time allowed between entering the queue and completing execution.
OptionalmaxMax number of tasks allowed in the queue at a time.
OptionalskipAllows to enqueue a task in the front of the queue, skipping all enqueued tasks.
false
import AsyncLock = require('async-lock');
const lock = new AsyncLock();
// Add a task to the front of the queue waiting for a given lock
lock.acquire(key, fn1, cb); // runs immediately
lock.acquire(key, fn2, cb); // added to queue
lock.acquire(key, priorityFn, cb, { skipQueue: true }); // jumps queue and runs before fn2
OptionaltimeoutMax amount of time an item can remain in the queue before acquiring the lock.
Use your own promise library instead of the global
Promisevariable.