Class: TaskProperty

TaskProperty()

new TaskProperty()

A TaskProperty is the Computed Property-like object returned from the task function. You can call Task Modifier methods on this object to configure the behavior of the Task.

See Managing Task Concurrency for an overview of all the different task modifiers you can use and how they impact automatic cancelation / enqueueing of task instances.

TaskProperty is only used for supporting "classic" Ember objects. When using Native JavaScript or TypeScript classes, you will use task decorators on methods instead.

Source:

Methods

cancelOn(eventNames*)

This behaves like the task(...).on() modifier, but instead will cause the task to be canceled if any of the specified events fire on the parent object.

See the Live Example

Parameters:
Name Type Description
eventNames* String
Source:

debug()

Logs lifecycle events to aid in debugging unexpected Task behavior. Presently only logs cancelation events and the reason for the cancelation, e.g. "TaskInstance 'doStuff' was canceled because the object it lives on was destroyed or unrendered"

Source:

drop()

Configures the task to immediately cancel (i.e. drop) any task instances performed when the task is already running at maxConcurrency. Sets default maxConcurrency to 1.

Source:

enqueue()

Configures the task to run task instances one-at-a-time in the order they were .perform()ed. Sets default maxConcurrency to 1.

Source:

evented()

Activates lifecycle events, allowing Evented host objects to react to task state changes.


export default Component.extend({
  uploadTask: task(function* (file) {
    // ... file upload stuff
  }).evented(),

  uploadedStarted: on('uploadTask:started', function(taskInstance) {
    this.analytics.track("User Photo: upload started");
  }),
});
Source:

group(groupPath)

Adds this task to a TaskGroup so that concurrency constraints can be shared between multiple tasks.

See the Task Group docs for more information

Parameters:
Name Type Description
groupPath String

A path to the TaskGroup property

Source:

keepLatest()

Configures the task to drop all but the most recently performed TaskInstance.

Source:

maxConcurrency(n)

Sets the maximum number of task instances that are allowed to run at the same time. By default, with no task modifiers applied, this number is Infinity (there is no limit to the number of tasks that can run at the same time). .restartable, .enqueue, and .drop set the default maxConcurrency to 1, but you can override this value to set the maximum number of concurrently running tasks to a number greater than 1.

See the AJAX Throttling example

The example below uses a task with maxConcurrency(3) to limit the number of concurrent AJAX requests (for anyone using this task) to 3.

doSomeAjax: task(function * (url) {
  return fetch(url);
}).maxConcurrency(3),

elsewhere() {
  this.doSomeAjax.perform("http://www.example.com/json");
},
Parameters:
Name Type Description
n Number

The maximum number of concurrently running tasks

Source:

observes(keys*)

This behaves like the task(...).on() modifier, but instead will cause the task to be performed if any of the specified properties on the parent object change.

Parameters:
Name Type Description
keys* String
Source:

on(eventNames*)

Calling task(...).on(eventName) configures the task to be automatically performed when the specified events fire. In this way, it behaves like Ember.on.

You can use task(...).on('init') to perform the task when the host object is initialized.

export default Component.extend({
  pollForUpdates: task(function * () {
    // ... this runs when the Component is first created
    // because we specified .on('init')
  }).on('init'),

  handleFoo: task(function * (a, b, c) {
    // this gets performed automatically if the 'foo'
    // event fires on this Component,
    // e.g., if someone called component.trigger('foo')
  }).on('foo'),
});
Parameters:
Name Type Description
eventNames* String
Source:

onState(callbacknullable)

Configures the task to call the passed in callback for derived state updates, overriding the default derived state tracking. You may call with null to completely opt-out of derived state tracking.

Parameters:
Name Type Attributes Description
callback function <nullable>

Callback to be called. Receives an object argument with the new state.

Source:

restartable()

Configures the task to cancel old currently task instances to make room for a new one to perform. Sets default maxConcurrency to 1.

See the Live Example

Source: