From 766c3b86ca2052b23c53a36f04109bb30f2c3cdd Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Tue, 25 Jun 2024 09:33:27 +0200 Subject: [PATCH] fix: forward dispatch return value --- lib/dispatcher/dispatcher.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/dispatcher/dispatcher.js b/lib/dispatcher/dispatcher.js index b1e0098ec4b..9ce5c20b780 100644 --- a/lib/dispatcher/dispatcher.js +++ b/lib/dispatcher/dispatcher.js @@ -39,18 +39,35 @@ class Dispatcher extends EventEmitter { } } +const kOnDrain = Symbol('onDrain') +const kOnConnect = Symbol('onConnect') +const kOnDisconnect = Symbol('onDisconnect') +const kOnConnectionError = Symbol('onConnectionError') + class ComposedDispatcher extends Dispatcher { - #dispatcher = null - #dispatch = null + #dispatcher + #dispatch constructor (dispatcher, dispatch) { super() + this.#dispatcher = dispatcher this.#dispatch = dispatch + + this[kOnDrain] = (...args) => this.emit('drain', ...args) + this[kOnConnect] = (...args) => this.emit('connect', ...args) + this[kOnDisconnect] = (...args) => this.emit('disconnect', ...args) + this[kOnConnectionError] = (...args) => this.emit('connectionError', ...args) + + this.#dispatcher + .on('drain', this[kOnDrain]) + .on('connect', this[kOnConnect]) + .on('disconnect', this[kOnDisconnect]) + .on('connectionError', this[kOnConnectionError]) } dispatch (...args) { - this.#dispatch(...args) + return this.#dispatch(...args) } close (...args) {