Barrier
Defined in: packages/async/src/synchro/barrier.ts:26
An asynchronous reusable barrier for N participants.
Barriers allow multiple asynchronous tasks to wait until a specified number of them have reached a certain point in their execution.
After the required number of tasks have called wait(), all waiting tasks
are released, and the barrier resets for reuse.
Example
Section titled “Example”const barrier = new Barrier(3);
async function task(id: number) { console.log(`Task ${id} is waiting at the barrier.`); await barrier.wait(); console.log(`Task ${id} has crossed the barrier.`); }
// Start 3 tasks that will wait at the barrier task(1); task(2); task(3);Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Barrier(
count):Barrier
Defined in: packages/async/src/synchro/barrier.ts:34
Create a Barrier for the specified number of participants.
Parameters
Section titled “Parameters”number
Number of participants required to release the barrier.
Returns
Section titled “Returns”Barrier
Methods
Section titled “Methods”wait()
Section titled “wait()”wait(
signal?):Promise<void>
Defined in: packages/async/src/synchro/barrier.ts:48
Wait for the barrier.
After releasing all waiters, the barrier resets for reuse.
Parameters
Section titled “Parameters”signal?
Section titled “signal?”AbortSignal | null
An optional AbortSignal to cancel the wait operation.
Returns
Section titled “Returns”Promise<void>
A promise that resolves when the barrier is released.