Class TaskGroup

Defined in: src/lib/taskgroup.coffee
Inherits: Interface

Overview

Our TaskGroup class.

Available configuration is documented in ::setConfig.

Available events:

Available internal statuses:

Class Method Summary

Instance Method Summary

Inherited Method Summary

Methods inherited from Interface

.whenDone, .onceDone, .done, .getNames, .getName, .getConfig

Class Method Details

TaskGroup .create(args...) Source

Creates a new TaskGroup instance.

Parameters:

  • (Arguments) argsThe {Arguments} to be forwarded along to the ::constructor.

Returns:

Boolean .isTaskGroup(group) Source

A helper method to check if the passed argument is an instanceof a TaskGroup.

Parameters:

  • (TaskGroup) itemThe possible instance of the TaskGroup that we want to check

Returns:

  • (Boolean) — Returns a Boolean of whether or not the item is a TaskGroup instance.

Constructor Details

::constructor(args...) Source

Initialize our new TaskGroup instance. Forwards arguments onto ::setConfig.

Instance Method Details

::addGroup(args...) Source

Add a TaskGroup with some configuration to ourself, create it if needed.

Parameters:

  • (Arguments) args{Arguments} to configure (and if needed, create) the TaskGroup

::addGroups(items, args...) Source

Add TaskGroups with some configuration to ourself, create it if needed.

Parameters:

  • (Array) itemsAn Array of TaskGroup items to add to ourself
  • (Arguments) argsOptional {Arguments} to configure each added TaskGroup

::addTask(args...) Source

Add a Task with some configuration to ourself, create it if needed.

Parameters:

  • (Arguments) args{Arguments} to configure (and if needed, create) the task

::addTasks(items, args...) Source

Add Tasks with some configuration to ourself, create it if needed.

Parameters:

  • (Array) itemsAn Array of Task items to add to ourself
  • (Arguments) argsOptional {Arguments} to configure each added Task

::clear() Source

Clear remaning items.

TaskGroup ::createGroup(args...) Source

Create a TaskGroup instance from some configuration.

If the first argument is already a TaskGroup instance, then just update it's configuration with the remaning arguments.

Parameters:

  • (Arguments) args{Arguments} to use to configure the TaskGroup instance

Returns:

Task ::createTask(args...) Source

Create a Task instance from some configuration.

If the first argument is already a Task instance, then just update it's configuration with the remaning arguments.

Parameters:

  • (Arguments) args{Arguments} to use to configure the Task instance

Returns:

  • (Task) — Returns the new Task instance

::destroy() Source

Destroy all remaining items and remove listeners.

Object ::getItemNames() Source

Gets the names of the items, the total number of items, and their results for the purpose of debugging.

Returns:

  • (Object) — Returns an Object containg the hashes:
    • (Array) remainingAn Array of the names of the remaining items
    • (Array) runningAn Array of the names of the running items
    • (Array) completedAn Array of the names of the completed items
    • (Number) totalA Number of the total items we have
    • (Array) resultsAn Array of the results of the compelted items

Object ::getItemTotals() Source

Gets the total number count of each of our item lists.

Returns:

  • (Object) — Returns an Object containg the hashes:
    • (Number) remainingA Number of the total remaining items
    • (Number) runningA Number of the total running items
    • (Number) completedA Number of the total completed items
    • (Number) totalA Number of the total items we have
    • (Number) resultsA Number of the total results we have

Number ::getItemsTotal() Source

Gets the total number of items

Returns:

  • (Number) — Returns a Number of the total items we have

Boolean ::hasExited() Source

Have we finished its execution yet?

Returns:

  • (Boolean) — Returns a Boolean which is true if we have finished execution

Boolean ::hasItems() Source

Whether or not we have any items

Returns:

  • (Boolean) — Returns a Boolean which is true if we have any running or remaining items

Boolean ::hasRemaining() Source

Whether or not we have any items that are yet to execute

Returns:

  • (Boolean) — Returns a Boolean which is true if we have any items that are still yet to be executed

Boolean ::hasRunning() Source

Whether or not we have any running items

Returns:

  • (Boolean) — Returns a Boolean which is true if we have any items that are currently running

Boolean ::hasStarted() Source

Have we started execution yet?

Returns:

  • (Boolean) — Returns a Boolean which is true if we have commenced execution

Boolean ::isComplete() Source

Have we completed its execution yet?

Completion of executed is determined of whether or not we have started, and whether or not we are currently paused or have no remaining and running items left

Returns:

  • (Boolean) — Returns a Boolean which is true if we have completed execution

Boolean ::isEmpty() Source

Whether or not we have no items left

Returns:

  • (Boolean) — Returns a Boolean which is true if we have no more running or remaining items

::onceDone(handler) Source

Once Done Promise. Fires the listener once, either on the next tick if we are already done, or if not, once the done event fires.

Parameters:

  • (Function) listenerThe Function to attach or execute.

::run(args...) Source

Start the execution.

::setConfig(opts = {}) Source

Set the configuration for our instance.

Despite accepting an Object of configuration, we can also accept an Array of configuration. When using an array, a String becomes the :name, a Function becomes the :method, and an Object becomes the :config

Parameters:

  • (Object) configOur configuration Object can contain the following fields:
    • (String) name(default: null) A String for what we would like our name to be, useful for debugging.
    • (Function) next(defualt: null) A Function that we would like bound to the done event once.
    • (Function) method(default: null) A Function that we would like to use to created nested groups and tasks using an inline style.
    • (TaskGroup) parent(default: null) A parent TaskGroup that we may be attached to.
    • (String) onError(default: 'exit') A String that is either 'exit' or 'ignore', when 'ignore' errors that occur within items will not halt execution and will not be reported in the completion callbacks err argument (but will still be in the results argument).
    • (Number) concurrency(default: 1) The Number of items that we would like to execute at the same time. Use 0 for unlimited. 1 accomplishes serial execution, everything else accomplishes parallel execution.
    • (Boolean) run(default: true) A Boolean for whether or not to the :method (if specified) automatically.
    • (Object) nestedConfig(default: null) An Object of nested configuration to be applied to all items of this group.
    • (Object) nestedTaskConfig(default: null) An Object of nested configuration to be applied to all Tasks of this group.
    • (Array) tasks(default: null) An Array of tasks to be added as children.
    • (Array) groups(default: null) An Array of groups to be added as children.
    • (Array) items(default: null) An Array of Task and/or TaskGroup instances to be added to this group.

::setNestedConfig(config = {}) Source

Set Nested Config

::setNestedTaskConfig(config = {}) Source

Set Nested Task Config

::whenDone(handler) Source

When Done Promise. Fires the listener, either on the next tick if we are already done, or if not, each time the done event fires.

Parameters:

  • (Function) listenerThe Function to attach or execute.