Skip to content

Commit

Permalink
fix: forward dispatch return value
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Jun 25, 2024
1 parent dd98299 commit 766c3b8
Showing 1 changed file with 20 additions and 3 deletions.
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

0 comments on commit 766c3b8

Please sign in to comment.