@adviser/cement - v0.0.0
    Preparing search index...

    Class WaitingForValue<T>

    A utility for managing a value that may not be immediately available. Allows multiple callers to await the same value efficiently, with all waiters resolved when the value becomes available.

    const waiting = new WaitingForValue<string>();

    // Multiple callers can await the value
    const promise1 = waiting.waitValue();
    const promise2 = waiting.waitValue();

    // Set the value - all waiters are resolved
    waiting.setValue(Option.Some("hello"));

    // Both promises resolve to "hello"

    Type Parameters

    • T = void

      The type of value being waited for

    Index

    Constructors

    Methods

    • Initializes or reinitializes the WaitingForValue with an optional preset value. If a preset value is provided and is Some, the value is immediately available. Otherwise, sets up the waiting mechanism for future value resolution.

      Parameters

      • presetValue: Option<T> = ...

        Optional initial value

      Returns void

    • Sets the value and resolves all pending waiters. If called when no value exists, resolves the waiting Future. If called when a value already exists, updates the value and resets the waiting mechanism. Does nothing if the provided value is None.

      Parameters

      • value: Option<T>

        The value to set (wrapped in Option)

      Returns void

    • Returns a promise that resolves when the value becomes available. If the value is already set, returns a promise that resolves immediately. Multiple calls to this method are safe and efficient - all callers share the same resolution logic thanks to ResolveOnce.

      Returns Promise<T>

      A promise that resolves to the value