Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Barrier

Barrier for critical sections.

The Barrier class blocks critical sections until the downward counter to be zero. Unlike the Latch class whose downward counter is disposable, Barrier can re-use the downward counter repeatedly, resetting counter to be initial value whenever reach to the zero.

author

Jeongho Nam - https://github.com/samchon

Hierarchy

  • Barrier

Index

Constructors

constructor

  • new Barrier(size: number): Barrier

Methods

arrive

  • arrive(n?: number): Promise<void>
  • Derecements the counter.

    Decrements the counter by n without blocking.

    If the parametric value n is equal to or greater than internal counter, so that the internal counter be equal to or less than zero, everyone who are waiting for the Latch would continue their executions.

    Parameters

    • Default value n: number = 1

      Value of the decrement. Default is 1.

    Returns Promise<void>

arrive_and_drop

  • arrive_and_drop(): Promise<void>
  • Decrements the counter and initial size at the same time.

    Decrements not only internal counter, but also initialize size of the counter at the same time. If the remained counter be zero by the decrement, everyone who are waiting for the Barrier would continue their executions.

    Returns Promise<void>

arrive_and_wait

  • arrive_and_wait(): Promise<void>
  • Decrements the counter and waits until the counter to be zero.

    Decrements the counter by one and blocks the section until internal counter to be zero.

    If the the remained counter be zero by this decrement, everyone who are waiting for the Barrier would continue their executions including this one.

    Returns Promise<void>

wait

  • wait(): Promise<void>
  • Waits until the counter to be zero.

    Blocks the function calling until internal counter to be reached to the zero.

    Returns Promise<void>

wait_for

  • wait_for(ms: number): Promise<boolean>
  • Tries to wait until the counter to be zero in timeout.

    Attempts to block the function calling until internal counter to be reached to the zero in timeout. If succeeded to waiting the counter to be reached to the zero, it returns true. Otherwise, the Barrier fails to reach to the zero in the given time, the function gives up the waiting and returns false.

    Parameters

    • ms: number

      The maximum miliseconds for waiting.

    Returns Promise<boolean>

    Whether succeeded to waiting in the given time.

wait_until

  • wait_until(at: Date): Promise<boolean>
  • Tries to wait until the counter to be zero in time expiration.

    Attempts to block the function calling until internal counter to be reached to the zero in time expiration. If succeeded to waiting the counter to be reached to the zero, it returns true. Otherwise, the Barrier fails to reach to the zero in the given time, the function gives up the waiting and returns false.

    Parameters

    • at: Date

      The maximum time point to wait.

    Returns Promise<boolean>

    Whether succeeded to waiting in the given time.

Generated using TypeDoc