Class GroupTask<T, R>

GroupTask class represents a kind of task which on execution runs its sub tasks in a defined mode.

Remarks

It must have the execution mode (or type, deprecated) and sub tasks defined in its configuration. It can optionally have a worker function and worker parameters in its configuration. It has an execute method which is used to run its sub tasks and store their results.

It can be a sub task of a group task.

Example

Group task with only required configuration.

const groupTask = GroupTask<[number, number], number>({
mode: "series" // or "parallel",
subTasks: [task1, task2], // at least 2 (or 1, deprecated)
});

Example

GroupTask with optional worker function and worker parameters.

const groupTask = GroupTask<[number, number], number>({
mode: "series" // or "parallel",
subTasks: [task1, task2], // at least 2
worker: (a, b) => a + b,
workerParams: [1, 2],
});

Type Parameters

  • T extends unknown[]

    The type of the task worker parameters.

  • R

    The type of the task worker result.

Hierarchy

Constructors

Accessors

Methods

Constructors

  • Type Parameters

    • T extends unknown[]

      The type of the task worker parameters.

    • R

      The type of the task worker result.

    Parameters

    • groupTaskConfig: GroupTaskConfigI<T, R>

      The configuration options for the group task.

    Returns GroupTask<T, R>

    Throws

    If no configuration is set.

    Throws

    If invalid mode is set.

    Throws

    If subtasks array is empty.

Accessors

Methods

  • Executes the group task.

    Parameters

    • fbConfig: TaskConfigI<T, R> = {}

      The fallback task configuration.

    Returns Promise<GroupTaskResultT<R>>

    The task worker result.

    Remarks

    All sub tasks must have a worker function and worker parameters defined at the time of execution.

    If any of the sub task have undefined worker function or worker parameters, then it should be set or it will use group task's worker function and worker parameters if defined, or fallback configuration can be provided to use for the execution, else it will throw an error.

    Fallback configuration does not set the worker function or worker parameters of the group task or its sub tasks but only provides the temporary values to fallback on.

    If even fallback values are undefined, then sub task throws an error.

    Example

    Without fallback configuration.

    groupTask.execute();
    // will run successfully if subtask.worker and subtask.workerParams are not undefined or
    // groupTask.worker and groupTask.workerParams are defined for fallback

    Example

    With a fallback worker function.

    groupTask.execute({ worker: (a, b) => a - b });
    // fallback worker function will be used only if subtask.worker and groupTask.worker are
    // undefined
    // will run successfully if subtask.workerParams is not undefined or
    // groupTask.workerParams is defined for fallback

    Example

    With fallback worker parameters.

    groupTask.execute({ worker: (a, b) => a - b });
    // fallback worker parameters will be used only if subtask.workerParams and
    // groupTask.workerParams are undefined
    // will run successfully if subtask.worker is not undefined or
    // groupTask.worker is defined for fallback

    Example

    With both fallback worker and worker parameters.

    task.execute({ worker: (a, b) => a - b, workerParams: [3, 4] });
    // fallback worker function will be used only if subtask.worker and groupTask.worker are
    // undefined
    // fallback worker parameters will be used only if subtask.workerParams and
    // groupTask.workerParams are undefined
    // will run successfully even if subtask.worker, subtask.workerParams, groupTask.worker,
    // and groupTask.workerParams are undefined

Generated using TypeDoc