Class: Task

Task()

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 TaskInstances, and at any point, you can call the .cancelAll() method on this object to cancel all running or enqueued TaskInstances.

Source:

Members

(readonly) isIdle :boolean

true if the task is not in the running or queued state.

Type:
  • boolean
Source:

(readonly) isQueued :boolean

true if any future task instances are queued.

Type:
  • boolean
Source:

(readonly) isRunning :boolean

true if any current task instances are running.

Type:
  • boolean
Source:

(readonly) last :TaskInstance

The most recently started task instance.

Type:
Source:

(readonly) lastCanceled :TaskInstance

The most recently canceled task instance.

Type:
Source:

(readonly) lastComplete :TaskInstance

The most recently completed task instance.

Type:
Source:

(readonly) lastErrored :TaskInstance

The most recent task instance that errored.

Type:
Source:

(readonly) lastIncomplete :TaskInstance

The most recent task instance that is incomplete.

Type:
Source:

(readonly) lastPerformed :TaskInstance

The most recently performed task instance.

Type:
Source:

(readonly) lastRunning :TaskInstance

The most recent task instance that is currently running.

Type:
Source:

(readonly) lastSuccessful :TaskInstance

The most recent task instance that succeeded.

Type:
Source:

(readonly) performCount :number

The number of times this task has been performed.

Type:
  • number
Source:

(readonly) state :string

The current state of the task: "running", "queued" or "idle".

Type:
  • string
Source:

Methods

(async) cancelAll()

Cancels all running or queued TaskInstances 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 ".cancelAll() was explicitly called on the Task".

options.resetState

If true, will clear the task state (last* and performCount properties will be set to initial values). Defaults to false.

Source:

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.

Source:

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

Source:
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.

Source: