Class: TaskGroupProperty

TaskGroupProperty()

new TaskGroupProperty()

"Task Groups" provide a means for applying task modifiers to groups of tasks. Once a Task is declared as part of a group task, modifiers like drop() or restartable() will no longer affect the individual Task. Instead those modifiers can be applied to the entire group.

import { task, taskGroup } from 'ember-concurrency';

export default Controller.extend({
  chores: taskGroup().drop(),

  mowLawn:       task(taskFn).group('chores'),
  doDishes:      task(taskFn).group('chores'),
  changeDiapers: task(taskFn).group('chores')
});
Source:

Methods

drop()

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

Source:

enqueue()

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

Source:

keepLatest()

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

Source:

maxConcurrency(n)

Sets the maximum number of task instances that are allowed to run in this task group 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 group with maxConcurrency(3) to limit the number of concurrent AJAX requests (for anyone using tasks in this group) to 3.

ajax: taskGroup().maxConcurrency(3),

doSomeAjax: task(function * (url) {
  return Ember.$.getJSON(url).promise();
}).group('ajax'),

doSomeAjax: task(function * (url) {
  return Ember.$.getJSON(url).promise();
}).group('ajax'),

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

The maximum number of concurrently running tasks

Source:

restartable()

Configures the task group 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: