diff options
Diffstat (limited to 'src/lib/Messages.js')
-rw-r--r-- | src/lib/Messages.js | 14 |
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 = { |