machty / ember-concurrency

ember-concurrency is an Ember Addon that enables you to write concise, worry-free, cancelable, restartable, asynchronous tasks.
http://ember-concurrency.com
MIT License
689 stars 157 forks source link

`task.cancelAll()` cancels all tasks on group (bug?) #335

Open danDanV1 opened 4 years ago

danDanV1 commented 4 years ago

Running task.cancelAll() on a task that is part of a group cancels all the tasks in the group.

Shouldn't fooTask.cancelAll() just cancel all the Foo tasks? and group.cancelAll() cancel all the tasks in a group?

In the below example, primaryQueueTask and backgroundQueueTask are members of queueGroup to limit maxConcurrency between them. backgroundQueueTask is an idle queue that runs only when there's no work to be done in primaryQueueTask.

When backgroundQueueTask.cancelAll() is run, all the tasks in primaryQueueTask get cancelled too.

Is this a bug?

init() {
    this._super(...arguments);

    //define property on init to use some dynamic values
    defineProperty(
      this,
      "queueGroup",
      taskGroup()
        .maxConcurrency(this.concurrentItems)
        .enqueue()
    );
  },
  primaryQueueTask: task(function*(component) {
      yield timeout(1000);
  }).group("queueGroup").debug(),

  backgroundQueueTask: task(function*(component) {
    if (this.primaryQueueTask.isQueued) {
      this.backgroundQueueTask.cancelAll()
      return;
    }
      yield timeout(1000);

  }).group("queueGroup").debug()

Debug

TaskInstance 'backgroundQueueTask' was canceled because .cancelAll() was explicitly called on the Task.
TaskInstance 'primaryQueueTask' was canceled because .cancelAll() was explicitly called on the Task.