xqhy1q
Last Updated: June 23, 2018
·
996
· fr0gs
Doggy

Ember.run.later and setTimeout comparing scenario.

In the Ember internals (Backburner) it can be found that Ember.run.later basically calls setTimeout() under the hood, but respecting the firing order by which other timeouts were added into the queue.
More on it on a blog post soon in www.estebansastre.com

import Ember from 'ember';

export default Ember.Controller.extend({
  appName: "Timers comparison",
  init: function() {
    this._super();
    this.set('myErrCountLater', 0);
    this.set('myErrCountTimeout', 0);
    this.myFunc(0);
    this.myOtherFunc(0);
  },
  myFunc: function(errorCount) {
    if (errorCount < 7) {
      self = this;
            this.set('myErrCountLater', errorCount);
        console.log("Error Count Later is " + errorCount + ", repeating");
      Ember.run.later(this, function () {
        return self.myFunc(errorCount+1);
      }, 1500);
    }
    else {
        console.log("Everything failed");
    }
    },
  myOtherFunc: function(errorCount) {
    if (errorCount < 7) {
      self = this;
      this.set('myErrCountTimeout', errorCount)
      console.log("Error Count Timeout is " + errorCount + ", repeating");
      setTimeout(function() {
        return self.myOtherFunc(errorCount + 1);
      }, 1500);
    }
    else {
      console.log("Everything failed");
    }
  }
});
Say Thanks
Respond

5 Responses
Add your response

29801

Before ember-concurrency, my team would hit this same acceptance-test-runs-forever problem with Ember.run.later. We worked around it by following 1 of 2 suggestions from emberjs/ember.js#3008: we switched to window.setTimeout and wrapped Ember-specific code in its callback in an Ember.run. This was preferable to the other workaround of maintaining test-specific code in app-code. The only drawback was slightly more code and the non-obviousness of using native window methods, when we tend to reach for Ember methods first. ember-concurrency could abstract this away. What would happen if ember-concurrency switched to window.setTimeout + Ember.run under the hood?
https://showbox.onl/
https://vidmate.onl/
https://mobdro.onl/

2 months ago ·
29861
about 2 months ago ·
30029

Showbox offers a clean user interface to give an amazing streaming experience. https://show-box.one/

6 days ago ·
30033

The app that checks all the vulnerabilities on your network. check out!!
https://getwpswpatester.com/

4 days ago ·
30048

You can use Ember.run.later like you would normally use setTimeout

Ember.run.later((function() {
//do something in here that will run in 2 seconds
}), 2000);

I'm not sure of the internals, but I know that integration testing Ember requires that you use run.later (if you don't the test code won't wait for the timeout to finish).
https://mobdro.ooo

1 day ago ·