From abb434ce7ca023da08da44c237915a046fce6475 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Thu, 27 Jan 2011 22:14:03 -0500 Subject: [PATCH] Add timeout arg to util.waitFor. --HG-- branch : key-processing --- common/content/events.js | 2 +- common/modules/completion.jsm | 4 +--- common/modules/util.jsm | 5 +++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/common/content/events.js b/common/content/events.js index ff6aaebf..a1393e60 100644 --- a/common/content/events.js +++ b/common/content/events.js @@ -916,7 +916,7 @@ var Events = Module("events", { let start = Date.now(); 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(); if (!buffer.loaded) diff --git a/common/modules/completion.jsm b/common/modules/completion.jsm index 9f291f02..afd866ac 100644 --- a/common/modules/completion.jsm +++ b/common/modules/completion.jsm @@ -804,9 +804,7 @@ var CompletionContext = Class("CompletionContext", { * If 0 or null, wait indefinitely. */ wait: function wait(interruptable, timeout) { - let end = Date.now() + timeout; - util.waitFor(function () !this.incomplete || (this.timeout && Date.now() > end), - this); + util.waitFor(function () !this.incomplete, this, timeout); return this.incomplete; } }, { diff --git a/common/modules/util.jsm b/common/modules/util.jsm index 01fce1ae..4459f597 100644 --- a/common/modules/util.jsm +++ b/common/modules/util.jsm @@ -1526,8 +1526,9 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), this.yielders--; } }, - waitFor: function waitFor(test, self, interruptable) { - while (!test.call(self)) + waitFor: function waitFor(test, self, timeout, interruptable) { + let end = timeout && Date.now() + timeout; + while ((!end || Date.now() < end) && !test.call(self)) this.threadYield(false, interruptable); },