remove listeners for command handlers

This commit is contained in:
Iuri Matias 2018-05-16 13:57:27 -04:00
parent 44d6cc32df
commit 4dcd644b7c
1 changed files with 5 additions and 2 deletions

View File

@ -40,9 +40,12 @@ EventEmitter.prototype.request = function() {
EventEmitter.prototype.setCommandHandler = function(requestName, cb) {
log("setting command handler for: ", requestName);
return this.on('request:' + requestName, function(_cb) {
let listener = function(_cb) {
cb.call(this, ...arguments);
});
}
// unlike events, commands can only have 1 handler
this.removeAllListeners('request:' + requestName);
return this.on('request:' + requestName, listener);
};
EventEmitter.prototype.setCommandHandlerOnce = function(requestName, cb) {