new Task()
The Task
object lives on a host Ember object (e.g.
a Component, Route, or Controller). You call the
.perform()
method on this object
to create run individual TaskInstance
s,
and at any point, you can call the .cancelAll()
method on this object to cancel all running or enqueued
TaskInstance
s.
Members
(readonly) isIdle :boolean
true
if the task is not in the running or queued state.
Type:
- boolean
(readonly) isQueued :boolean
true
if any future task instances are queued.
Type:
- boolean
(readonly) isRunning :boolean
true
if any current task instances are running.
Type:
- boolean
(readonly) last :TaskInstance
The most recently started task instance.
Type:
(readonly) lastCanceled :TaskInstance
The most recently canceled task instance.
Type:
(readonly) lastComplete :TaskInstance
The most recently completed task instance.
Type:
(readonly) lastErrored :TaskInstance
The most recent task instance that errored.
Type:
(readonly) lastIncomplete :TaskInstance
The most recent task instance that is incomplete.
Type:
(readonly) lastPerformed :TaskInstance
The most recently performed task instance.
Type:
(readonly) lastRunning :TaskInstance
The most recent task instance that is currently running.
Type:
(readonly) lastSuccessful :TaskInstance
The most recent task instance that succeeded.
Type:
(readonly) performCount :number
The number of times this task has been performed.
Type:
- number
(readonly) state :string
The current state of the task: "running"
, "queued"
or "idle"
.
Type:
- string
Methods
(async) cancelAll()
Cancels all running or queued TaskInstance
s for this Task.
If you're trying to cancel a specific TaskInstance (rather
than all of the instances running under this task) call
.cancel()
on the specific TaskInstance.
Parameters:
Name | Type | Description |
---|---|---|
options.reason |
A descriptive reason the task was
cancelled. Defaults to |
|
options.resetState |
If true, will clear the task state
( |
linked()
Flags the task as linked to the parent task's lifetime. Must be called within another task's perform function. The task will be cancelled if the parent task is canceled as well.
ember-concurrency will indicate when this may be needed.
perform(arg*)
Creates a new TaskInstance
and attempts to run it right away.
If running this task instance would increase the task's concurrency
to a number greater than the task's maxConcurrency, this task
instance might be immediately canceled (dropped), or enqueued
to run at later time, after the currently running task(s) have finished.
Parameters:
Name | Type | Description |
---|---|---|
arg* |
* | args to pass to the task function |
Fires:
- TaskInstance#event:TASK_NAME:started
- TaskInstance#event:TASK_NAME:succeeded
- TaskInstance#event:TASK_NAME:errored
- TaskInstance#event:TASK_NAME:canceled
unlinked()
Flags the task as not linked to the parent task's lifetime. Must be called within another task's perform function. The task will NOT be cancelled if the parent task is canceled.
This is useful for avoiding the so-called "self-cancel loop" for tasks. ember-concurrency will indicate when this may be needed.