@ac-essentials/misc-util
    Preparing search index...

    Class Barrier

    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.

    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);
    Index

    Constructors

    Methods

    Constructors

    Methods

    • Wait for the barrier.

      After releasing all waiters, the barrier resets for reuse.

      Parameters

      • Optionalsignal: AbortSignal | null

        An optional AbortSignal to cancel the wait operation.

      Returns Promise<void>

      A promise that resolves when the barrier is released.