diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index ee2b95382..a6eb924c6 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -1509,6 +1509,26 @@ if(appInfo.platformVersion[0] >= 2) { window.zoteroLastRepaint = now; }; + /** + * Pumps a generator until it yields false. See schema.js for an example. + */ + this.pumpGenerator = function(generator) { + _waiting++; + + 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--; + } + }} + timer.initWithCallback(timerCallback, ms, Components.interfaces.nsITimer.TYPE_REPEATING_SLACK); + // add timer to global scope so that it doesn't get garbage collected before it completes + _runningTimers.push(timer); + } + /** * Emulates the behavior of window.setTimeout, but ensures that callbacks do not get called * during Zotero.wait()