semaphore-async-await
Options
All
  • Public
  • Public/Protected
  • All
Menu

A lock that can be used to synchronize critical sections in your code. For more details on how to use this class, please view the documentation of the Semaphore class from which Lock inherits.

Hierarchy

Index

Constructors

constructor

Methods

acquire

  • acquire(): Promise<boolean>

drainPermits

  • drainPermits(): number
  • Acquires all permits that are currently available and returns the number of acquired permits.

    Returns number

    Number of acquired permits.

execute

  • execute<T>(func: function): Promise<T>
  • Schedules func to be called once a permit becomes available. Returns a promise that resolves to the return value of func.

    Type parameters

    • T

      The return type of func.

    Parameters

    • func: function

      The function to be executed.

        • (): T
        • Returns T

    Returns Promise<T>

    A promise that gets resolved with the return value of the function.

getPermits

  • getPermits(): number

release

  • release(): void

signal

  • signal(): void
  • Increases the number of permits by one. If there are other functions waiting, one of them will continue to execute in a future iteration of the event loop.

    Returns void

tryAcquire

  • tryAcquire(): boolean
  • Synchronous function that tries to acquire a permit and returns true if successful, false otherwise.

    Returns boolean

    Whether a permit could be acquired.

wait

  • wait(): Promise<boolean>
  • Returns a promise used to wait for a permit to become available. This method should be awaited on.

    Returns Promise<boolean>

    A promise that gets resolved when execution is allowed to proceed.

waitFor

  • waitFor(milliseconds: number): Promise<boolean>
  • Same as Semaphore.wait except the promise returned gets resolved with false if no permit becomes available in time.

    Parameters

    • milliseconds: number

      The time spent waiting before the wait is aborted. This is a lower bound, don't rely on it being precise.

    Returns Promise<boolean>

    A promise that gets resolved with true when execution is allowed to proceed or false if the time given elapses before a permit becomes available.

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc