Options
All
  • Public
  • Public/Protected
  • All
Menu

Class MemoryLock

Lock that is used to synchronize execution within one process using shared memory.

Remember: This implementation is not suitable for synchronization of distributed processes.

Configuration parameters

  • options:
    • retry_timeout: timeout in milliseconds to retry lock acquisition. (Default: 100)
see

ILock

see

Lock

Example

let lock = new MemoryLock();

lock.acquire("123", "key1", (err) => {
    if (err == null) {
        try {
            // Processing...
        } finally {
            lock.releaseLock("123", "key1", (err) => {
                // Continue...
            });
        }
    }
});

Hierarchy

Implements

Index

Methods

acquireLock

  • acquireLock(correlationId: string, key: string, ttl: number, timeout: number, callback: function): void
  • Makes multiple attempts to acquire a lock by its key within give time interval.

    Parameters

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • key: string

      a unique lock key to acquire.

    • ttl: number

      a lock timeout (time to live) in milliseconds.

    • timeout: number

      a lock acquisition timeout.

    • callback: function

      callback function that receives error or null for success.

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

configure

  • configure(config: ConfigParams): void
  • Configures component by passing configuration parameters.

    Parameters

    • config: ConfigParams

      configuration parameters to be set.

    Returns void

releaseLock

  • releaseLock(correlationId: string, key: string, callback?: function): void
  • Releases the lock with the given key.

    Parameters

    • correlationId: string

      not used.

    • key: string

      the key of the lock that is to be released.

    • Optional callback: function

      (optional) the function to call once the lock has been released. Will be called with null.

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

tryAcquireLock

  • tryAcquireLock(correlationId: string, key: string, ttl: number, callback: function): void
  • Makes a single attempt to acquire a lock by its key. It returns immediately a positive or negative result.

    Parameters

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • key: string

      a unique lock key to acquire.

    • ttl: number

      a lock timeout (time to live) in milliseconds.

    • callback: function

      callback function that receives a lock result or error.

        • (err: any, result: boolean): void
        • Parameters

          • err: any
          • result: boolean

          Returns void

    Returns void

Generated using TypeDoc