Task

Task class

Constructor

new Task()

Create a task

Parameters:
NameTypeDescription
options.namestring

Task name

options.dependsArray.<string>

List of tasks this task depends on

options.execTaskExec

Function to run. You must either implement Task.exec or provide a function here.

options.context*

Context data for this task (optional)

options.backgroundbool

Extends

Methods

(async) assertCancelled()

Assert cancelled

(async) assertNotCancelled()

Assert not cancelled

backgroundReject(value)

Reject a background task as a failure. This should be used in the stop handler of background tasks.

Parameters:
NameTypeDescription
value*

backgroundResolve(value)

Resolve a background task as a success. This should be used in the stop handler of background tasks.

Parameters:
NameTypeDescription
value*

(async) cancel()

Cancel task

detach() → {Promise.<any>}

Begin background task. Only can be used by background tasks.

Returns:

A promise which resolves/rejects based on calls to Task.backgroundResolve and Task.backgroundReject.

Type: 
Promise.<any>

(async) exec() → {*}

All tasks must either implement this function or provide a exec function at construction time. Foreground tasks are expected to do their work and return any data as quickly as possible. Returned data is made available to any tasks that named this task as a depedency. Background tasks are expected to return this.detach() and manage their state with the this.backgroundResolve and this.backgroundReject functions. If an unexpected exception occurs it will be recorded in Task.failure.

Parameters:
NameTypeDescription
options.taskTask

The task that is running

options.dependsCollection.<string, Task>

Collection of completed depended tasks (mapped by name).

Returns:

Return any data you want dependant tasks to recieve in their options.depend. Return value will be stored in Task.success. If an unexpected exception occurs it will be recorded in Task.failure.

Type: 
*

(async) stop()

All background tasks must implement this function. Do not call this function directly, use Task.cancel(). Background tasks must manage the task result with the Task.backgroundResolve() and Task.backgroundReject() functions.

Type Definitions

Properties

Properties
NameTypeDescription
namestring

Task name

backgroundbool

Background task

dependsArray.<string>

List of task names this task depends upon

createdNumber

Unix time ms this task was instantiated

startedNumber

Unix time ms the task began running exec function

finishedNumber

Unix time ms the task completed running exec function

donebool

Task has completed?

success*

Task success value if one was returned by exec

failure*

Task failure value if one was returned by exec

Events

done

Done event.

Type:

failure

Failure event.

Type:

pre-failure

Pre-failure event.

Type:

pre-success

Pre-success event.

Type:

running

Running event.

Type:

success

Success event.

Type: