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:

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: