1

I am using ember-concurrency where I have to make API calls every 10 seconds and update the setup status for my application install phase. If there is an error, then I need the timeout value to be 1 seconds instead if default value of 10 seconds. Seems like every time timeout value is 10 seconds only and even with an error, user is on the screen for 10 seconds and then sees an error modal. Can anyone tell what can be a possible solution? or what I am doing wrong?

induceWait: task(function*() {
  while (continue) {
   // make the api call here
   //if error in any evaluating conditons, set timeout value to be 1 seconds, else 10 seconds
   this.get('store').findAll('status').then((response) => {
     if (response.flag) {
        this.set('timeout', 10000);
     } else {
        this.set('timeout', 1000);
      }
   }, (error) => {

   });
   yield timeout(this.get('timeout');
   this.get('induceWait').perform();
}
NullVoxPopuli
  • 61,906
  • 73
  • 206
  • 352
Bhavya Bansal
  • 257
  • 1
  • 15

1 Answers1

3

I think the root of the issue here is that the promise itself needs to be yielded. So, what's happening currently is that the promise 'starts', and then you yield a timeout with whatever timeout is set to before your promise resolves.

in this example, I've used a local variable, and changed the name to delayMs to avoid a naming collision with the timeout function

induceWait: task(function*() {
  while (true) {

  let delayMs = 1000;

  const response = yield this.get('store').findAll('status');

  if (response.flag) {
    delayMs = 10000;
  } 

  yield timeout(delayMs);

  this.get('induceWait').perform();
}
NullVoxPopuli
  • 61,906
  • 73
  • 206
  • 352