Class Task

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

Overview

Our Task Class.

Available configuration is documented in ::setConfig.

Available events:

Available internal statuses:

Examples:

Class Method Summary

Instance Method Summary

Inherited Method Summary

Methods inherited from Interface

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

Class Method Details

Task .create(args...) Source

Creates a new Task instance.

Parameters:

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

Returns:

  • (Task) — Returns the new Task instance.

Boolean .isTask(item) Source

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

Parameters:

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

Returns:

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

Constructor Details

::constructor(args...) Source

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

Instance Method Details

::destroy() Source

Destroy the task and prevent it from executing ever again.

Boolean ::hasExited() Source

Have we finished its execution yet?

Returns:

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

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?

Returns:

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

Boolean ::isDestroyed() Source

Have we been destroyed?

Returns:

  • (Boolean) — Returns a Boolean which is true if we have bene destroyed

::onceDone(listener) 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() Source

Start the execution of the task.

Will emit an error event if the task has already started before.

::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) The Function that we would like to execute within our task.
    • (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' duplicate run errors are not reported, useful when combined with the timeout option.
    • (Array) args(default: null) An Array of arguments that we would like to forward onto our method when we execute it.
    • (Number) timeout(default: null) A Number of millesconds that we would like to wait before timing out the method.

::whenDone(listener) 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.