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

    Class Future<T, CTX>

    A Promise that can be resolved or rejected externally after creation.

    Future provides a way to create a Promise whose resolution is controlled externally rather than in the executor function. This is useful for coordinating async operations, implementing custom async primitives, or bridging callback-based APIs to promises.

    const future = new Future<string>();

    // Later, resolve it from anywhere
    future.resolve('hello');

    // Or reject it
    future.reject(new Error('failed'));

    // Use it like a promise
    const result = await future.asPromise();

    Type Parameters

    • T

      The type of the resolved value

    • CTX = void

      Optional context type for additional data

    Index

    Constructors

    Properties

    Methods

    Constructors

    Properties

    ctx?: CTX
    id: () => string = ...

    Lazily-generated unique identifier for this Future. Not cryptographically secure, but suitable for transaction/debug tracking.

    Methods

    • Returns the underlying Promise that will be resolved or rejected.

      Returns Promise<T>

      The Promise representation of this Future

    • Resolves the Future with the given value.

      Parameters

      • value: T

        The value to resolve the Promise with

      Returns void

    • Rejects the Future with the given reason.

      Parameters

      • reason: unknown

        The reason for rejection (typically an Error)

      Returns void