The promise implementing by an Constructable#construction.

interface Construction<T> {
    constructor: any;
    change: Observable<[status: Lifecycle.Status, subject: T], void>;
    closed: Promise<T>;
    error?: Error;
    isErrorHandled: boolean;
    ready: Promise<T>;
    status: Lifecycle.Status;
    assert(description?: string): void;
    assert<T>(description: string, dependency: undefined | T): T;
    close(destructor?: (() => MaybePromise)): MaybePromise;
    crash(cause?: any): void;
    onCompletion(actor: (() => void)): void;
    onError(actor: ((error: Error) => MaybePromise<void>)): void;
    onSuccess(actor: (() => MaybePromise<void>)): void;
    setStatus(status: Lifecycle.Status): void;
    start<const T, const A, const This>(this: This, ...args: A): void;
    toString(): string;
}

Type Parameters

  • T

Hierarchy

  • Promise<T>
    • Construction

Constructors

constructor: any

Properties

change: Observable<[status: Lifecycle.Status, subject: T], void>

Notifications of state change. Normally you just await construction but this offers more granular events and repeating events.

closed: Promise<T>

Resolves when destruction completes; rejects if the component crashes.

Handling errors on this promise will prevent other handlers from seeing the primary cause.

error?: Error

If construction ends with an error, the error is saved here.

isErrorHandled: boolean

True iff the primary error has been or will be reported.

ready: Promise<T>

Resolves when construction completes; rejects if construction crashes.

Behaves identically to Construction but always throws the primary cause rather than CrashedDependencyError.

Handling errors on this promise will prevent other handlers from seeing the primary cause.

Status of the constructed object.

Methods

  • Throws an error if construction is ongoing or incomplete.

    Parameters

    • Optionaldescription: string

    Returns void

  • Asserts construction is complete and that an object is defined.

    Type Parameters

    • T

    Parameters

    • description: string
    • dependency: undefined | T

    Returns T

  • Invoke destruction logic then move to destroyed status.

    Typically you invoke this in the subject's "close" method.

    Use of this function is optional. It provides these benefits:

    • Ensures the subject is fully initialized before closing.

    • Handles and logs errors, ensuring close() always completes successfully.

    • Makes destruction observable via change and closed.

    Parameters

    Returns MaybePromise

  • Move subject to "crashed" state, optionally setting the cause.

    This happens automatically if there is an error during construction. It is also useful for post-construction errors to convey crashed state to components such as the environmental runtime service.

    Parameters

    • Optionalcause: any

    Returns void

  • Invoke a method after construction completes successfully or onsuccessfully.

    Errors thrown by this callback are logged but otherwise ignored.

    Parameters

    • actor: (() => void)
        • (): void
        • Returns void

    Returns void

  • Invoke a method after construction completes unsuccessfully.

    If you register an onError handler then the default error handler will not log the error.

    Errors thrown by this callback are logged but otherwise ignored.

    Parameters

    Returns void

  • Invoke a method after construction completes successfully.

    Errors thrown by this callback are logged but otherwise ignored.

    Parameters

    Returns void

  • Manually force a specific status.

    This offers flexibility in component lifecycle management including resetting component to inactive state and broadcasting lifecycle changes. On reset listeners are also reset and must be reinstalled.

    This method fails if initialization is ongoing; await completion first.

    Parameters

    Returns void

  • If you omit the initializer parameter to Construction execution is deferred until you invoke this method to initiate construction via the Constructable.Deferred interface.

    Unlike the initializer, errors are always reported via the PromiseLike interface even if the constructable throws an error synchronously.

    Type Parameters

    Parameters

    Returns void

  • Returns a string representation of an object.

    Returns string