@types/async-lock

  • Version 1.3.0
  • Published
  • 7.69 kB
  • No dependencies
  • MIT license

Install

npm i @types/async-lock
yarn add @types/async-lock
pnpm add @types/async-lock

Overview

TypeScript definitions for async-lock

Index

Classes

class AsyncLock

class AsyncLock {}

    constructor

    constructor(options?: AsyncLock.AsyncLockOptions);

      property DEFAULT_MAX_OCCUPATION_TIME

      static readonly DEFAULT_MAX_OCCUPATION_TIME: number;

        property DEFAULT_MAX_PENDING

        static readonly DEFAULT_MAX_PENDING: number;

          property DEFAULT_TIMEOUT

          static readonly DEFAULT_TIMEOUT: number;

            method acquire

            acquire: {
            <T>(
            key: string | string[],
            fn:
            | (() => T | PromiseLike<T>)
            | ((done: AsyncLock.AsyncLockDoneCallback<T>) => any),
            opts?: AsyncLock.AsyncLockOptions
            ): Promise<T>;
            <T>(
            key: string | string[],
            fn: (done: AsyncLock.AsyncLockDoneCallback<T>) => any,
            cb: AsyncLock.AsyncLockDoneCallback<T>,
            opts?: AsyncLock.AsyncLockOptions
            ): void;
            };
            • Lock on asynchronous code.

              Parameter key

              resource key or keys to lock

              Parameter fn

              function to execute

              Parameter opts

              options

              Example 1

              import AsyncLock = require('async-lock'); const lock = new AsyncLock();

              lock.acquire( key, () => { // return value or promise }, opts ).then(() => { // lock released });

            • Lock on asynchronous code.

              Parameter key

              resource key or keys to lock

              Parameter fn

              function to execute

              Parameter cb

              callback function

              Parameter opts

              options

              Example 1

              import AsyncLock = require('async-lock'); const lock = new AsyncLock();

              lock.acquire( key, (done) => { // async work done(err, ret); }, (err, ret) => { // lock released }, opts );

            method isBusy

            isBusy: (key?: string) => boolean;
            • Whether there is any running or pending async function.

            Interfaces

            interface AsyncLockOptions

            interface AsyncLockOptions {}

              property domainReentrant

              domainReentrant?: boolean | undefined;
              • Make a lock reentrant in the same domain.

                false

                Example 1

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

              property maxOccupationTime

              maxOccupationTime?: number | undefined;
              • Max amount of time allowed between entering the queue and completing execution.

                0 (Never)

              property maxPending

              maxPending?: number | undefined;
              • Max number of tasks allowed in the queue at a time.

                1000

              property Promise

              Promise?: unknown;
              • Use your own promise library instead of the global Promise variable.

                Example 1

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

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

              property skipQueue

              skipQueue?: boolean | undefined;
              • Allows to enqueue a task in the front of the queue, skipping all enqueued tasks.

                false

                Example 1

                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

              property timeout

              timeout?: number | undefined;
              • Max amount of time an item can remain in the queue before acquiring the lock.

                0 (Never)

              Type Aliases

              type AsyncLockDoneCallback

              type AsyncLockDoneCallback<T> = (err?: Error | null, ret?: T) => void;

                Package Files (1)

                Dependencies (0)

                No dependencies.

                Dev Dependencies (0)

                No dev dependencies.

                Peer Dependencies (0)

                No peer dependencies.

                Badge

                To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/async-lock.

                • Markdown
                  [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@types/async-lock)
                • HTML
                  <a href="https://www.jsdocs.io/package/@types/async-lock"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>