1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-22 17:55:46 +01:00

Add timeout arg to util.waitFor.

--HG--
branch : key-processing
This commit is contained in:
Kris Maglione
2011-01-27 22:14:03 -05:00
parent 7f15781e41
commit abb434ce7c
3 changed files with 5 additions and 6 deletions

View File

@@ -916,7 +916,7 @@ var Events = Module("events", {
let start = Date.now(); let start = Date.now();
let end = start + (maxWaitTime * 1000); let end = start + (maxWaitTime * 1000);
util.waitFor(function () !events.feedingKeys || buffer.loaded || Date.now() > end); util.waitFor(function () !events.feedingKeys || buffer.loaded, this, maxWaitTime);
commandline.clear(); commandline.clear();
if (!buffer.loaded) if (!buffer.loaded)

View File

@@ -804,9 +804,7 @@ var CompletionContext = Class("CompletionContext", {
* If 0 or null, wait indefinitely. * If 0 or null, wait indefinitely.
*/ */
wait: function wait(interruptable, timeout) { wait: function wait(interruptable, timeout) {
let end = Date.now() + timeout; util.waitFor(function () !this.incomplete, this, timeout);
util.waitFor(function () !this.incomplete || (this.timeout && Date.now() > end),
this);
return this.incomplete; return this.incomplete;
} }
}, { }, {

View File

@@ -1526,8 +1526,9 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
this.yielders--; this.yielders--;
} }
}, },
waitFor: function waitFor(test, self, interruptable) { waitFor: function waitFor(test, self, timeout, interruptable) {
while (!test.call(self)) let end = timeout && Date.now() + timeout;
while ((!end || Date.now() < end) && !test.call(self))
this.threadYield(false, interruptable); this.threadYield(false, interruptable);
}, },