Skip to content

Commit

Permalink
Merge pull request #321 from tulios/only-emit-events-if-there-are-lis…
Browse files Browse the repository at this point in the history
…teners

Only emit events if there are listeners
  • Loading branch information
tulios committed Apr 1, 2019
1 parent 695164c commit d6b88a5
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/instrumentation/emitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ module.exports = class InstrumentationEventEmitter {
throw new KafkaJSError('Invalid event name', { retriable: false })
}

const event = new InstrumentationEvent(eventName, payload)
this.emitter.emit(eventName, event)
if (this.emitter.listenerCount(eventName) > 0) {
const event = new InstrumentationEvent(eventName, payload)
this.emitter.emit(eventName, event)
}
}

/**
Expand Down

0 comments on commit d6b88a5

Please sign in to comment.