Constructor
new Task()
Create a task
Name | Type | Description |
---|---|---|
options.name | string | Task name |
options.depends | Array.<string> | List of tasks this task depends on |
options.exec | TaskExec | Function to run. You must either implement |
options.context | * | Context data for this task (optional) |
options.background | bool |
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.
Name | Type | Description |
---|---|---|
value | * |
backgroundResolve(value)
Resolve a background task as a success. This should be used in the stop handler of background tasks.
Name | Type | Description |
---|---|---|
value | * |
(async) cancel()
Cancel task
detach() → {Promise.<any>}
Begin background task. Only can be used by background tasks.
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
.
Name | Type | Description |
---|---|---|
options.task | Task | The task that is running |
options.depends | Collection.<string, Task> | Collection of completed depended tasks (mapped by name). |
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
PropertiesName | Type | Description |
---|---|---|
name | string | Task name |
background | bool | Background task |
depends | Array.<string> | List of task names this task depends upon |
created | Number | Unix time ms this task was instantiated |
started | Number | Unix time ms the task began running exec function |
finished | Number | Unix time ms the task completed running exec function |
done | bool | 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.
failure
Failure event.
pre-failure
Pre-failure event.
pre-success
Pre-success event.
running
Running event.
success
Success event.