A resource is extended component that represent the access to an external/internal resource, besides the error handling and identity, it has a start, stop and close methods to manage the resource lifecycle. It also has a checks property to define the checks that will be performed over the resource to achieve the resulted status. The most typical example of a resource are the Provider that allow to access to external databases, message brokers, etc.

interface Resource {
    checks: Checks;
    close: () => Promise<void>;
    componentId: string;
    name: string;
    start: () => Promise<void>;
    status: "pass" | "fail" | "warn";
    stop: () => Promise<void>;
    on(event: "error", listener: (error: Multi | Error | Crash) => void): this;
    on(
        event: "status",
        listener: (status: "pass" | "fail" | "warn") => void,
    ): this;
}

Hierarchy (View Summary)

Implemented by

Properties

checks: Checks

Checks performed over this component to achieve the resulted status

close: () => Promise<void>

Resource close function

componentId: string

Component identifier

name: string

Component name

start: () => Promise<void>

Resource start function

status: "pass" | "fail" | "warn"

Resource status

stop: () => Promise<void>

Resource stop function

Methods

  • Add a listener for the error event, emitted when the component detects an error.

    Parameters

    • event: "error"

      error event

    • listener: (error: Multi | Error | Crash) => void

      Error event listener

    Returns this

  • Add a listener for the status event, emitted when the component status changes.

    Parameters

    • event: "status"

      status event

    • listener: (status: "pass" | "fail" | "warn") => void

      Status event listener

    Returns this