Stop iterating when StopIteration thrown from generator
This commit is contained in:
parent
27b95ebb14
commit
50a793c4ea
1 changed files with 13 additions and 4 deletions
|
@ -1502,11 +1502,20 @@ if(appInfo.platformVersion[0] >= 2) {
|
|||
var timer = Components.classes["@mozilla.org/timer;1"].
|
||||
createInstance(Components.interfaces.nsITimer);
|
||||
var timerCallback = {"notify":function() {
|
||||
if(!generator.next()) {
|
||||
timer.cancel();
|
||||
_runningTimers.splice(_runningTimers.indexOf(timer), 1);
|
||||
_waiting--;
|
||||
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();
|
||||
_runningTimers.splice(_runningTimers.indexOf(timer), 1);
|
||||
_waiting--;
|
||||
|
||||
if(err) throw err;
|
||||
}}
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue