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
691 stars 155 forks source link

waitForProperty not resolving for encapsulated taskInstance return value #459

Open colenso opened 2 years ago

colenso commented 2 years ago

I've created a dummy project to demo this: https://github.com/colenso/concurrency-test

@task encapsulatedTask = {
    *perform(value) {
      console.log('encapsulated waiting for 5 seconds');
      yield timeout(5000);
      console.log('encapsulated all done waiting');
      return 'all good';
    }
  }

  @task
  *printEncapsulatedTaskValue() {
    this.encapsulatedTask.perform();
    let value = yield waitForProperty(this.encapsulatedTask, 'last.value');
    console.log('encapsulated value: ', value);
  }

In the code above ☝️ the encapsulated value is never printed to the console. We do however see the logs to indicate that the encapsulatedTask ran fine.

However for a normal task like:

@task
  *normalTask() {
    console.log('normal: waiting for 5 seconds');
    yield timeout(5000);
    console.log('normal: all done waiting');
    return 'all good';
  }

  @task
  *printNormalTaskValue() {
    this.normalTask.perform();
    let value = yield waitForProperty(this.normalTask, 'last.value');
    console.log('normal value: ', value);
  }

The waitForProperty resolves just fine and we get to see normal value: all good on the console.