Manages task execution, including queue management, progress control, and event handling.

Supports sequential and parallel execution modes and provides methods to query, retrieve, and manage task results.

Hierarchy

  • TaskManagerBase
    • TaskManager

Constructors

Properties

_flags: Set<TaskManagerFlag> = ...

Current flags for the task manager.

Empty set of flags.
_mode: ExecutionMode = ExecutionMode.SEQUENTIAL

Current execution mode of the task manager.

ExecutionMode.SEQUENTIAL
_progress: number = 0

Current progress of tasks, represented as a value between 0 and 1.

0
_status: TaskManagerStatus = "idle"

Current status of the task manager.

"idle"
flowController: FlowController = ...

Manages task execution and flow control.

query: TaskQuery = ...

Query interface for accessing and managing tasks.

Accessors

  • get progress(): number
  • Retrieves the current progress of tasks.

    Returns number

  • set progress(progress: number): void
  • Updates the progress of tasks.

    Parameters

    • progress: number

      New progress value (0 to 1).

    Returns void

    progress - When progress changes.

    param - When the progress parameter changes.

Methods

  • 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
    
  • 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

    Parameters

    • type: TType

      The identifier for the event type to emit.

    • ...data: TaskManagerEvents[TType] extends void ? [] : [data: TaskManagerEvents[TType]]

      The data to pass to the event listeners. The type of this data is defined by the corresponding value in TEvents.

    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

    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

    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);
    });
  • Sets the progress of tasks.

    Parameters

    • progress: number

      Progress value to set.

    Returns TaskManager

    Instance of the task manager for chaining.

    progress - When progress changes.

    param - When the progress parameter changes.

  • Starts executing tasks in the queue.

    Parameters

    • Optionalforce: boolean

      If true, starts even if the manager is in an error state.

    Returns Promise<void | TaskManager>

    A promise that resolves when execution starts.

    progress - When task progress updates.

    success - When all tasks complete successfully.

    error - When a task or the manager encounters an error.

    fail - When a task fails and the CONTINUE_ON_ERROR flag is not set.