Base class for managing task statuses, progress, flags, and event-driven operations.

Provides foundational methods for task lifecycle management and event handling, used by task group implementations.

Hierarchy (View Summary)

Constructors

Properties

_flags: Set<"CONTINUE_ON_ERROR"> = ...

Current flags for the task group.

Empty set of flags.
_progress: number = 0

Progress of the task group, represented as a value between 0 and 1.

0
_status: TaskGroupStatus = "idle"

Current status of the task group.

"idle"

Accessors

  • get flags(): "CONTINUE_ON_ERROR"[]
  • Current flags for the task group.

    Returns "CONTINUE_ON_ERROR"[]

    Empty array of flags.
    
  • set flags(flags: Set<"CONTINUE_ON_ERROR">): void
  • Updates the flags for the task group.

    Parameters

    • flags: Set<"CONTINUE_ON_ERROR">

      New set of flags to apply.

    Returns void

    param - When the flags parameter changes.

  • get progress(): number
  • Progress of the task group, represented as a value between 0 and 1.

    Returns number

    0
    
  • set progress(progress: number): void
  • Updates the progress of the task group.

    Parameters

    • progress: number

      New progress value (0 to 1).

    Returns void

    progress - When progress changes.

    param - When the progress parameter changes.

Methods

  • Adds a flag to the task group.

    Parameters

    • flag: "CONTINUE_ON_ERROR"

      Flag to add.

    Returns this

    Instance of the task group for chaining.

    param - When the flags parameter changes.

  • 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: TaskGroupEvents[TType] extends void ? [] : [data: TaskGroupEvents[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!"));
  • Checks if a specific flag is set in the task group.

    Parameters

    • flag: "CONTINUE_ON_ERROR"

      Flag to check.

    Returns boolean

    true if the flag is set.

  • Checks if all specified flags are set in the task group.

    Parameters

    • ...flags: "CONTINUE_ON_ERROR"[]

      Flags to check.

    Returns boolean

    true if all specified flags are set.

  • 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);
    });
  • Removes a flag from the task group.

    Parameters

    • flag: "CONTINUE_ON_ERROR"

      Flag to remove.

    Returns this

    Instance of the task group for chaining.

    param - When the flags parameter changes.