Stop iterating when StopIteration thrown from generator
This commit is contained in:
parent
27b95ebb14
commit
50a793c4ea
|
@ -1502,11 +1502,20 @@ if(appInfo.platformVersion[0] >= 2) {
|
||||||
var timer = Components.classes["@mozilla.org/timer;1"].
|
var timer = Components.classes["@mozilla.org/timer;1"].
|
||||||
createInstance(Components.interfaces.nsITimer);
|
createInstance(Components.interfaces.nsITimer);
|
||||||
var timerCallback = {"notify":function() {
|
var timerCallback = {"notify":function() {
|
||||||
if(!generator.next()) {
|
var err = false;
|
||||||
|
try {
|
||||||
|
if(generator.next()) return;
|
||||||
|
} catch(e if e.toString() === "[object StopIteration]") {
|
||||||
|
// There must be a better way to perform this check
|
||||||
|
} catch(e) {
|
||||||
|
err = e;
|
||||||
|
}
|
||||||
|
|
||||||
timer.cancel();
|
timer.cancel();
|
||||||
_runningTimers.splice(_runningTimers.indexOf(timer), 1);
|
_runningTimers.splice(_runningTimers.indexOf(timer), 1);
|
||||||
_waiting--;
|
_waiting--;
|
||||||
}
|
|
||||||
|
if(err) throw err;
|
||||||
}}
|
}}
|
||||||
timer.initWithCallback(timerCallback, ms ? ms : 0, Components.interfaces.nsITimer.TYPE_REPEATING_SLACK);
|
timer.initWithCallback(timerCallback, ms ? ms : 0, Components.interfaces.nsITimer.TYPE_REPEATING_SLACK);
|
||||||
// add timer to global scope so that it doesn't get garbage collected before it completes
|
// add timer to global scope so that it doesn't get garbage collected before it completes
|
||||||
|
|
Loading…
Reference in New Issue
Block a user