Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: forward dispatch return value #3368

Merged
merged 4 commits into from
Jun 27, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions lib/dispatcher/dispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading