Main better lock class.

Hierarchy

  • BetterLock

Constructors

Properties

Methods

Constructors

Properties

DEFAULT_OPTIONS: BetterLockOptions = ...

Default options to be used when creating BetterLock instances.

Methods

  • Abort all jobs for a given key (or from the default job queue, if no key is given). Job executors will not be called. Callbacks will be called with JobAbortedError. Currently executing job will not be interrupted.

    Parameters

    Returns void

  • abortAll(): void
  • Abort all pending jobs from all queues. Currently executing jobs will not be interrupted.

    Returns void

  • Acquire the lock for given key or list of keys. If waiting on a list, keys will be acquired in order, as they become free. Any deadlock prevention must be handled by the caller.

    Once the lock is acquired, we will call the executor function, with a "done" method. You must call "done" to release the lock. Alternatively, return a Promise; lock will be released once promise resolves or rejects.

    Return values from your executor will be passed to callback (or the resulting promise).

    Type Parameters

    • TResult

    Parameters

    Returns Promise<TResult>

  • Acquire the lock for given key or list of keys. If waiting on a list, keys will be acquired in order, as they become free. Any deadlock prevention must be handled by the caller.

    Once the lock is acquired, we will call the executor function, with a "done" method. You must call "done" to release the lock. Alternatively, return a Promise; lock will be released once promise resolves or rejects.

    Return values from your executor will be passed to callback (or the resulting promise).

    Type Parameters

    • TResult

    Parameters

    Returns Promise<TResult>

  • Acquire the lock for given key or list of keys. If waiting on a list, keys will be acquired in order, as they become free. Any deadlock prevention must be handled by the caller.

    Once the lock is acquired, we will call the executor function, with a "done" method. You must call "done" to release the lock. Alternatively, return a Promise; lock will be released once promise resolves or rejects.

    Return values from your executor will be passed to callback (or the resulting promise).

    Type Parameters

    • TResult

    Parameters

    • executor: ICallbackExecutor<TResult>

      Function that will run inside the lock. Required.

    • callback: ICallback<TResult>

      Function to be called after the executor finishes or if we never enter the lock (timeout, queue depletion). Leave out to use promises.

    • Optional jobOptions: BetterLockJobOptions

      Options to be applied on this job only

    Returns void

  • Acquire the lock for given key or list of keys. If waiting on a list, keys will be acquired in order, as they become free. Any deadlock prevention must be handled by the caller.

    Once the lock is acquired, we will call the executor function, with a "done" method. You must call "done" to release the lock. Alternatively, return a Promise; lock will be released once promise resolves or rejects.

    Return values from your executor will be passed to callback (or the resulting promise).

    Type Parameters

    • TResult

    Parameters

    • key: BetterLockKey | BetterLockKey[]

      Named key or array of keys for this particular call. Calls with different keys will be run in parallel. Not required.

    • executor: IPromiseExecutor<TResult>

      Function that will run inside the lock. Required.

    • Optional jobOptions: BetterLockJobOptions

      Options to be applied on this job only

    Returns Promise<TResult>

  • Acquire the lock for given key or list of keys. If waiting on a list, keys will be acquired in order, as they become free. Any deadlock prevention must be handled by the caller.

    Once the lock is acquired, we will call the executor function, with a "done" method. You must call "done" to release the lock. Alternatively, return a Promise; lock will be released once promise resolves or rejects.

    Return values from your executor will be passed to callback (or the resulting promise).

    Type Parameters

    • TResult

    Parameters

    • key: BetterLockKey | BetterLockKey[]

      Named key or array of keys for this particular call. Calls with different keys will be run in parallel. Not required.

    • executor: ICallbackExecutor<TResult>

      Function that will run inside the lock. Required.

    • Optional jobOptions: BetterLockJobOptions

      Options to be applied on this job only

    Returns Promise<TResult>

  • Acquire the lock for given key or list of keys. If waiting on a list, keys will be acquired in order, as they become free. Any deadlock prevention must be handled by the caller.

    Once the lock is acquired, we will call the executor function, with a "done" method. You must call "done" to release the lock. Alternatively, return a Promise; lock will be released once promise resolves or rejects.

    Return values from your executor will be passed to callback (or the resulting promise).

    Type Parameters

    • TResult

    Parameters

    • key: BetterLockKey | BetterLockKey[]

      Named key or array of keys for this particular call. Calls with different keys will be run in parallel. Not required.

    • executor: ICallbackExecutor<TResult>

      Function that will run inside the lock. Required.

    • callback: ICallback<TResult>

      Function to be called after the executor finishes or if we never enter the lock (timeout, queue depletion). Leave out to use promises.

    • Optional jobOptions: BetterLockJobOptions

      Options to be applied on this job only

    Returns void

  • canAcquire(key?: string): boolean
  • Returns true if the caller can immediately acquire the lock. There is nothing holding the key and nothing in the queue.

    Parameters

    • Optional key: string

    Returns boolean

Generated using TypeDoc