@bluelibs/runner - v5.5.0
    Preparing search index...

    Class RunResult<V>

    RunResult represents the runtime instance after executing run(root). It provides access to tasks, events, resources, and lifecycle management.

    Key features:

    • Task execution via runTask()
    • Event emission via emitEvent()
    • Resource access via getResourceValue() / getLazyResourceValue()
    • Root access via getRootValue(), getRootConfig(), getRootId()
    • Disposal via dispose()
    const runtime = await run(app);
    const result = await runtime.runTask(myTask, { input: "data" });
    await runtime.dispose();

    Type Parameters

    • V

    Implements

    Index

    Constructors

    • Creates a new RunResult instance.

      Type Parameters

      • V

      Parameters

      • logger: Logger

        The framework logger for runtime diagnostics

      • store: Store

        The central store containing all registered tasks, events, resources

      • eventManager: EventManager

        Handles event emission and hook execution

      • taskRunner: TaskRunner

        Executes tasks with middleware and validation

      • disposeFn: () => Promise<void>

        Callback to clean up all resources during disposal

      Returns RunResult<V>

    Properties

    emitEvent: {
        <P>(
            event: string | IEvent<P>,
            payload?: P extends void | undefined ? undefined : P,
        ): Promise<void>;
        <P>(
            event: string | IEvent<P>,
            payload: P extends void | undefined ? undefined : P,
            options: IEventEmitOptions & { report: true },
        ): Promise<IEventEmitReport>;
        <P>(
            event: string | IEvent<P>,
            payload?: P extends void | undefined ? undefined : P,
            options?: IEventEmitOptions,
        ): Promise<void | IEventEmitReport>;
    } = ...

    Emits an event to trigger all registered hooks listening for it.

    Events are emitted synchronously or asynchronously depending on hook configuration. Hooks execute in order based on their order() value (lower runs first).

    The event definition or event ID string to emit

    The event payload data

    Emission options (failureMode, throwOnError, report)

    Promise by default, or IEventEmitReport if report: true

    // Basic emission
    await runtime.emitEvent(userRegistered, { userId: "123", email: "a@b.com" });

    // With report for hook failure tracking
    const report = await runtime.emitEvent(notify, undefined, { report: true });
    if (report.failedListeners.length > 0) {
    console.error("Failed hooks:", report.failedListeners);
    }
    logger: Logger

    Framework logger for diagnostics and debugging. Use this for logging within tasks or hooks.

    store: Store

    Central store containing all registered definitions. Provides access to tasks, events, resources, and their metadata.

    Accessors

    • get value(): V

      Returns the root value initialized by the root resource. Only available after the root resource has been initialized.

      Returns V

    Methods

    • Disposes the runtime and all registered resources.

      Disposal executes in reverse initialization order:

      1. All resource dispose methods are called
      2. Event listeners are cleared
      3. Async contexts are reset

      After disposal, any further operations will throw. Safe to call multiple times (subsequent calls return immediately).

      Returns Promise<void>

      Promise that resolves when disposal is complete

      RuntimeError if called during bootstrap phase

      await runtime.dispose();
      // All resources cleaned up, runtime is now inactive
    • Initializes (if not already) and returns the value of a resource on-demand.

      This method is useful when:

      • Lazy loading is enabled and the resource wasn't initialized at startup
      • You need to access a resource that may not have been loaded yet
      • You want to ensure initialization happens before access

      Type Parameters

      • Output extends Promise<any>

      Parameters

      • resource:
            | string
            | IResource<
                any,
                Output,
                any,
                any,
                any,
                TagType[],
                ResourceMiddlewareAttachmentType[],
            >

        The resource definition or resource ID string

      Returns Promise<Output extends Promise<U> ? U : Output>

      The initialized value of the resource (unwrapped if Promise-based)

      RuntimeError if resource not found or runtime disposed

      // Lazy-load a resource on demand
      const heavyService = await runtime.getLazyResourceValue(heavyService);
    • Retrieves the configuration that was passed to a resource.

      This returns the config object (the input), not the initialized value. Use getResourceValue() to get the initialized value.

      Type Parameters

      • Config

      Parameters

      • resource:
            | string
            | IResource<
                Config,
                any,
                any,
                any,
                any,
                TagType[],
                ResourceMiddlewareAttachmentType[],
            >

        The resource definition or resource ID string

      Returns Config

      The config object passed when registering the resource

      RuntimeError if resource not found or runtime disposed

      const config = runtime.getResourceConfig(server);
      // config = { port: 3000 }
    • Synchronously retrieves the initialized value of a resource.

      The resource must have been initialized (either at startup or via lazy loading). For resources not initialized at startup, use getLazyResourceValue() instead.

      Type Parameters

      • Output extends Promise<any>

      Parameters

      • resource:
            | string
            | IResource<
                any,
                Output,
                any,
                any,
                any,
                TagType[],
                ResourceMiddlewareAttachmentType[],
            >

        The resource definition or resource ID string

      Returns Output extends Promise<U> ? U : Output

      The initialized value of the resource (unwrapped if Promise-based)

      RuntimeError if resource not found, not initialized, or runtime disposed

      // Get initialized resource
      const db = runtime.getResourceValue(database);
      const config = runtime.getResourceValue("app.config");
    • Returns the ID of the root resource.

      Returns string

      The root resource identifier

      const rootId = runtime.getRootId(); // "app"
      
    • Returns the initialized value of the root resource.

      This is the value returned by the root resource's init function. The root must have been fully initialized before calling this.

      Type Parameters

      • Value = unknown

      Returns Value

      The root resource's initialized value

      RuntimeError if root hasn't been initialized yet

      const app = runtime.getRootValue<App>();
      
    • Executes a registered task within the runtime context.

      The task runs through its full middleware pipeline including:

      • Input validation (via inputSchema)
      • Middleware (retry, cache, timeout, etc.)
      • The task's core logic
      • Result validation (via resultSchema)

      Type Parameters

      • TTask extends
            | string
            | ITask<
                any,
                Promise<any>,
                any,
                any,
                TagType[],
                TaskMiddlewareAttachmentType[],
            >

      Parameters

      Returns TTask extends ITask<any, O, any, any, TagType[], TaskMiddlewareAttachmentType[]>
          ? O
          : Promise<any>

      // Run with task definition
      const result = await runtime.runTask(createUser, { name: "Alice" });

      // Run with options for journal forwarding
      const result = await runtime.runTask(greet, undefined, { journal });
    • Configures lazy loading options for resources. Used to enable on-demand resource initialization.

      Parameters

      • options: RunResultLazyOptions

        Lazy mode configuration

      Returns void

    • Sets the root value after the root resource initializes.

      Parameters

      • value: V | undefined

        The initialized root value

      Returns void