Manages task execution flow by organizing tasks into states (pending, active, and completed).

These states are part of the FlowController structure and do not belong to the tasks themselves.

Hierarchy

Constructors

Properties

active: Map<string, ExecutableTask> = ...

Tasks currently in progress.

completed: Map<string, { task: ExecutableTask; valid: boolean }> = ...

Tasks that have completed execution.

pending: Map<string, ExecutableTask> = ...

Tasks ready to start but not yet executed.

Accessors

Methods

  • Calculates the progress of tasks.

    Parameters

    • OptionalerrorSuccess: boolean

      Whether tasks with errors should count as fully progressed.

    Returns number

    Progress as a number between 0 and 1.

  • Removes all listeners for all event types, as well as all global listeners.

    Returns this

    The EventEmitter instance itself, allowing for method chaining.

    emitter.clear(); // No more event listeners remain
    
  • Moves tasks from active to completed.

    Parameters

    • taskId: string | string[]

      ID/s of task/s to complete.

    • OptionalvalidityCheck: (task: ExecutableTask) => boolean

      An optional callback to determine if the task is valid.

    Returns void

    transition - For each task, emits a transition from active to completed.

  • Emits an event of a specific type, invoking all registered listeners for that event type with the provided data. Also calls any global event listeners with a GlobalEvent object.

    Type Parameters

    • TType extends "transition"

      Event type.

    Parameters

    Returns this

    The EventEmitter instance itself, allowing for method chaining.

    emitter.emit("data", "Sample data");
    emitter.emit("loaded");
    emitter.emit("error", new Error("Oh no!"));
  • Removes a previously registered event listener for a specified event type. Use this method to unregister listeners when they are no longer needed, preventing potential memory leaks.

    Type Parameters

    • TType extends "transition"

      Event type.

    Parameters

    Returns this

    The EventEmitter instance itself, allowing for method chaining.

    const onError = (error: Error) => console.error(error);

    emitter.on("error", onError);

    // ...

    emitter.off("error", onError);
  • Removes a previously registered global event listener.

    Parameters

    Returns this

    The EventEmitter instance itself, allowing for method chaining.

    const globalListener = (event: GlobalEvent<TEvents>) => {
    console.log(`Event of type ${String(event.type)} received`, event.data);
    };

    emitter.onAll(globalListener);

    // ...

    emitter.offAll(globalListener);
  • Adds an event listener for a specified event type. This method allows you to specify which event you are interested in listening to and to provide a callback function that will be executed whenever that event is emitted.

    Type Parameters

    • TType extends "transition"

      Event type.

    Parameters

    Returns this

    The EventEmitter instance itself, allowing for method chaining.

    emitter.on("data", (data: string) => {
    console.log("Data", data);
    });

    emitter.on("loaded", function () {
    console.log(
    "Emitter loaded",
    this // EventEmitter<MyEvents>
    );
    });

    emitter.on("error", (error: Error) => {
    console.error(`Error: ${error.message}`);
    });
  • Adds a global event listener that is called for every emitted event.

    Parameters

    Returns this

    The EventEmitter instance itself, allowing for method chaining.

    emitter.onAll((event: GlobalEvent<TEvents>) => {
    console.log(`Event of type ${String(event.type)} received`, event.data);
    });
  • Moves all tasks from pending to active and executes a callback for each task.

    Parameters

    • callback: (task: ExecutableTask) => void

      Function to execute for each task.

    Returns (validityCheck?: (task: ExecutableTask) => boolean) => void

    A cleanup function to mark tasks as completed. The cleanup function accepts an optional validityCheck callback, which determines if each task should be marked as valid. The validityCheck is called for each task and should return true for valid tasks and false otherwise.

    transition - For each task, emits a transition from pending to active.