Options
All
  • Public
  • Public/Protected
  • All
Menu

A distributed, concurrent countdown latch data structure.

ICountDownLatch is a cluster-wide synchronization aid that allows one or more callers to wait until a set of operations being performed in other callers completes.

ICountDownLatch count can be reset using trySetCount() method after a countdown has finished but not during an active count. This allows the same latch instance to be reused.

There is no await() method to do an unbound wait since this is undesirable in a distributed application: for example, a cluster can split, or the master and replicas could all die. In most cases, it is best to configure an explicit timeout, so you have the ability to deal with these situations.

All of the API methods in the ICountDownLatch offer the exactly-once execution semantics. For instance, even if a countDown() call is internally retried because of crashed Hazelcast member, the counter value is decremented only once.

Hierarchy

Index

Methods

  • await(timeout: number): Promise<boolean>
  • Causes the call to wait until the latch has counted down to zero, or an exception is thrown, or the specified waiting time elapses.

    If the current count is zero then the promise resolves immediately with the value true.

    If the current count is greater than zero, then the promise is fulfilled only when one of the following things happen:

    • the count reaches zero due to invocations of the `countDown()` method,
    • this ICountDownLatch instance is destroyed,
    • the countdown owner becomes disconnected,
    • the specified waiting time elapses.

    If the count reaches zero, then the method returns with the value true.

    throws

    IllegalStateError if the Hazelcast instance was shut down while waiting

    Parameters

    • timeout: number

      timeout in milliseconds to wait for the count to reach zero; if the timeout is less than or equal to zero, the method will not wait at all

    Returns Promise<boolean>

    true if the count reached zero, false if the waiting time elapsed before the count reached zero

  • countDown(): Promise<void>
  • Decrements the count of the latch, releasing all waiting calls if the count reaches zero.

    If the current count is greater than zero, then it is decremented. If the new count is zero, then all waiting callers are notified and can proceed, and the countdown owner is set to null.

    If the current count equals zero, then nothing happens.

    Returns Promise<void>

  • destroy(): Promise<void>
  • Destroys this object cluster-wide. Clears all resources taken for this object.

    Returns Promise<void>

  • getCount(): Promise<number>
  • Returns the current count.

    Returns Promise<number>

    the current count

  • getName(): string
  • Returns the unique name of this object.

    Returns string

  • getPartitionKey(): string
  • Returns the key of the partition that this DistributedObject is assigned to. For a partitioned data structure, the returned value will not be null, but otherwise undefined.

    Returns string

  • getServiceName(): string
  • trySetCount(count: number): Promise<boolean>
  • Sets the count to the given value if the current count is zero.

    If count is not zero, then this method does nothing and returns false.

    Parameters

    • count: number

      the number of times countDown() must be invoked before callers can pass through await()

    Returns Promise<boolean>

    true if the new count was set, false if the current count is not zero

Generated using TypeDoc