1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-01-07 23:04:17 +01:00

Bang on tests some more. Ameliorate some async completion issues.

--HG--
extra : rebase_source : 0f550b1650963e4010e447db2df7d6815627bae2
This commit is contained in:
Kris Maglione
2011-02-01 04:02:29 -05:00
parent e38f408b5d
commit a21db1858a
7 changed files with 174 additions and 107 deletions

View File

@@ -437,18 +437,32 @@ var Addons = Module("addons", {
context.completions = types.map(function (t) [t, util.capitalize(t)]);
}
if (AddonManager.getAllAddons)
context.incomplete = true;
context.generate = function generate() {
update(base);
if (AddonManager.getAllAddons) {
context.incomplete = true;
if (AddonManager.getAllAddons)
AddonManager.getAllAddons(function (addons) {
context.incomplete = false;
update(array.uniq(base.concat(addons.map(function (a) a.type)),
true));
});
}
}
}
completion.extension = function extension(context, types) {
context.title = ["Extension"];
context.anchored = false;
context.keys = { text: "name", description: "description", icon: "iconURL" },
context.incomplete = true;
context.generate = function () {
AddonManager.getAddonsByTypes(types || ["extension"], function (addons) {
context.incomplete = false;
context.completions = addons;
});
};
};
}
});

View File

@@ -798,14 +798,14 @@ var CompletionContext = Class("CompletionContext", {
/**
* Wait for all subcontexts to complete.
*
* @param {boolean} interruptible When true, the call may be interrupted
* via <C-c>, in which case, "Interrupted" may be thrown.
* @param {number} timeout The maximum time, in milliseconds, to wait.
* If 0 or null, wait indefinitely.
* @param {boolean} interruptible When true, the call may be interrupted
* via <C-c>, in which case, "Interrupted" may be thrown.
*/
wait: function wait(interruptable, timeout) {
util.waitFor(function () !this.incomplete, this, timeout);
return this.incomplete;
wait: function wait(timeout, interruptable) {
this.allItems;
return util.waitFor(function () !this.incomplete, this, timeout, interruptable);
}
}, {
Sort: {
@@ -852,7 +852,7 @@ var Completion = Module("completion", {
return { items: res.map(function (i) ({ item: i })) };
context.contexts["/run"].completions = res;
}
context.wait(true);
context.wait(null, true);
return context.allItems;
},
@@ -866,7 +866,7 @@ var Completion = Module("completion", {
context.maxItems = maxItems;
context.fork.apply(context, ["list", 0, this, name].concat(Array.slice(arguments, 3)));
context = context.contexts["/list"];
context.wait();
context.wait(null, true);
let contexts = context.contextList.filter(function (c) c.hasItems && c.items.length);
if (!contexts.length)

View File

@@ -1536,10 +1536,19 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
this.yielders--;
}
},
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);
let end = timeout && Date.now() + timeout, result;
let timer = services.Timer(function () {}, 10, services.Timer.TYPE_REPEATING_SLACK);
try {
while (!(result = test.call(self)) && (!end || Date.now() < end))
this.threadYield(false, interruptable);
}
finally {
timer.cancel();
}
return result;
},
yieldable: function yieldable(func)