Options
All
  • Public
  • Public/Protected
  • All
Menu

A simple asynchronous lock that can be held by one task at a time.

This is a naive implementation that is meant for simple cases where two pieces of async test logic must not be run in parallel because they use the same resource.

Hierarchy

  • AsyncMutex

Index

Constructors

Properties

Methods

Constructors

Properties

awaiters: PromiseAndValueCallback<null>[]
held: number

Methods

  • acquire(): Promise<void>
  • Acquires the lock as soon as possible.

    Returns Promise<void>

    a Promise that resolves once the lock has been acquired

  • do<T>(action: () => Promise<T>): Promise<T>
  • Acquires the lock, awaits an asynchronous action, and ensures that the lock is released.

    Type parameters

    • T

    Parameters

    • action: () => Promise<T>

      an asynchronous function

        • (): Promise<T>
        • Returns Promise<T>

    Returns Promise<T>

    the function's return value.

  • release(): void
  • Releases the lock. If someone else was waiting on an acquire, they will now acquire it (first come first served). This simple implementation does not verify that you were the one who had actually acquired the lock.

    Returns void

Generated using TypeDoc