Ability to remove handlers from worker-channel and metadata-manager

This commit is contained in:
yflory
2019-08-16 11:09:24 +02:00
parent ba24cde76d
commit 656b129543
3 changed files with 22 additions and 6 deletions

View File

@@ -81,17 +81,25 @@ define([
// If the type is a query, your handler will be invoked with a reply function that takes
// one argument (the content to reply with).
chan.on = function (queryType, handler, quiet) {
(handlers[queryType] = handlers[queryType] || []).push(function (data, msg) {
var h = function (data, msg) {
handler(data.content, function (replyContent) {
postMsg(JSON.stringify({
txid: data.txid,
content: replyContent
}));
}, msg);
});
};
(handlers[queryType] = handlers[queryType] || []).push(h);
if (!quiet) {
event('EV_REGISTER_HANDLER', queryType);
}
return {
stop: function () {
var idx = handlers[queryType].indexOf(h);
if (idx === -1) { return; }
handlers[queryType].splice(idx, 1);
}
};
};
// If a particular handler is registered, call the callback immediately, otherwise it will be called