what is the Ember implementation of setInterval and clearInterval
I'm not aware of any equivalent, but I use such a code to have the functionality:
var Poller = Ember.Object.extend({
_interval: 1000,
_currentlyExecutedFunction: null,
start: function(context, pollingFunction) {
this.set('_currentlyExecutedFunction', this._schedule(context, pollingFunction, [].slice.call(arguments, 2)));
},
stop: function() {
Ember.run.cancel(this.get('_currentlyExecutedFunction'));
},
_schedule: function(context, func, args) {
return Ember.run.later(this, function() {
this.set('_currentlyExecutedFunction', this._schedule(context, func, args));
func.apply(context, args);
}, this.get('_interval'));
},
setInterval: function(interval) {
this.set('_interval', interval);
}
});
export
default Poller;
Then, you instantiate the poller: var poller = Poller.create()
and then you can play with poller.start()
and poller.stop()
+ set set the interval via poller.setInterval(interval)
.
In my code, I did more or less that way (polling the reports every 10 seconds):
_updateRunningReport: function(report) {
var poller = new Poller();
poller.setInterval(this.POLLING_INTERVAL);
poller.start(this, function() {
if (report.isRunning()) {
this._reloadReport(report);
} else {
poller.stop();
}
});
eventBus.onLogout(function() {
poller.stop();
});
},
Hope this helps...