summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorhackademix2018-08-28 01:23:27 +0200
committerhackademix2018-08-28 17:21:56 +0200
commite8716657e43c46a97d80783593a8f90786a24558 (patch)
treecfb32205c1002d3ce21f8687fe39965dbc91116a /src/lib
parent5bfba8a40fb591d9023ee113965fadcd733ba931 (diff)
downloadnoscript-e8716657e43c46a97d80783593a8f90786a24558.tar.gz
noscript-e8716657e43c46a97d80783593a8f90786a24558.tar.xz
noscript-e8716657e43c46a97d80783593a8f90786a24558.zip
Reordered startup sequence to be more friendly with embedders like the Tor Browser.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/Messages.js14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/lib/Messages.js b/src/lib/Messages.js
index a58598a..50639ef 100644
--- a/src/lib/Messages.js
+++ b/src/lib/Messages.js
@@ -1,17 +1,23 @@
"use strict";
{
let handlers = new Set();
-
- let forever = new Promise(resolve => {});
+
let dispatch = async (msg, sender) => {
let {_messageName} = msg;
+ let answers = [];
for (let h of handlers) {
let f = h[_messageName];
if (typeof f === "function") {
- return await f(msg, sender);
+ answers.push(f(msg, sender));
}
}
- await forever;
+ if (answers.length) {
+ return await (
+ answers.length === 1 ? answers.pop(): Promise.all(answers)
+ );
+ }
+ console.log("Answering %s", _messageName);
+ return undefined;
};
var Messages = {