AsyncLockOptions interface

Properties

domainReentrant

Make a lock reentrant in the same domain.

Example

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
        });
    });
});
maxExecutionTime

Max amount of time allowed between acquiring the lock and completing execution.

maxOccupationTime

Max amount of time allowed between entering the queue and completing execution.

maxPending

Max number of tasks allowed in the queue at a time.

Promise

Use your own promise library instead of the global Promise variable.

Example

import AsyncLock = require('async-lock');
import Bluebird = require('bluebird');
import Q = require('q');

new AsyncLock({ Promise: Bluebird }); // Bluebird
new AsyncLock({ Promise: Q });        // Q
skipQueue

Allows to enqueue a task in the front of the queue, skipping all enqueued tasks.

Example

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
timeout

Max amount of time an item can remain in the queue before acquiring the lock.

Property Details

domainReentrant

Make a lock reentrant in the same domain.

Example

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
        });
    });
});
domainReentrant?: boolean

Property Value

boolean

maxExecutionTime

Max amount of time allowed between acquiring the lock and completing execution.

maxExecutionTime?: number

Property Value

number

maxOccupationTime

Max amount of time allowed between entering the queue and completing execution.

maxOccupationTime?: number

Property Value

number

maxPending

Max number of tasks allowed in the queue at a time.

maxPending?: number

Property Value

number

Promise

Use your own promise library instead of the global Promise variable.

Example

import AsyncLock = require('async-lock');
import Bluebird = require('bluebird');
import Q = require('q');

new AsyncLock({ Promise: Bluebird }); // Bluebird
new AsyncLock({ Promise: Q });        // Q
Promise?: unknown

Property Value

unknown

skipQueue

Allows to enqueue a task in the front of the queue, skipping all enqueued tasks.

Example

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
skipQueue?: boolean

Property Value

boolean

timeout

Max amount of time an item can remain in the queue before acquiring the lock.

timeout?: number

Property Value

number