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

    Class Latch

    An asynchronous reusable latch for N participants.

    All waiters are released together when the latch is released (countdown reaches zero).

    After releasing all waiters, the latch remains released.

    const latch = new Latch(3);

    async function task(id: number) {
    console.log(`Task ${id} is waiting at the latch.`);
    await latch.wait();
    console.log(`Task ${id} has crossed the latch.`);
    }

    // Start 3 tasks that will wait at the latch
    task(1);
    task(2);
    task(3);

    // Simulate some work before counting down
    setTimeout(() => {
    console.log("Counting down the latch");
    latch.countDown();
    latch.countDown();
    latch.countDown();
    }, 1000);
    Index

    Constructors

    Accessors

    Methods

    Constructors

    Accessors

    Methods

    • Wait for the latch to be released. Resolves when countDown() has been called count times.

      Parameters

      • Optionalsignal: AbortSignal | null

        An optional AbortSignal to cancel the wait operation.

      Returns Promise<void>

      A promise that resolves when the latch is released.