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

    Class Condition

    A condition variable primitive.

    Allows tasks to wait until they are signaled to continue.

    const mutex = new Mutex();
    const condition = new Condition();
    let ready = false;

    // Task 1
    async function task1() {
    await mutex.lock();
    while (!ready) {
    await condition.wait(mutex);
    }
    // Proceed with task
    mutex.unlock();
    }

    // Task 2
    async function task2() {
    await mutex.lock();
    ready = true;
    condition.signal(); // or condition.broadcast() to wake all waiting tasks
    mutex.unlock();
    }
    Index

    Constructors

    Methods

    Constructors

    Methods

    • Wait until the condition is signaled.

      Parameters

      • lock: ILock

        The lockable (mutex) to use for synchronization.

      • Optionalsignal: AbortSignal | null

        An optional AbortSignal to cancel the wait operation.

      Returns Promise<void>

      A promise that resolves when the condition is signaled.