Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Overload eventemitter on method to handle data listeners #269

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
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
11 changes: 11 additions & 0 deletions lib/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const defaultOptions = {
};

Provider.prototype = Object.create(EventEmitter.prototype);
Provider.prototype.oldOn = Provider.prototype.on;
Provider.prototype.constructor = Provider;

Provider.prototype._applyDefaultOptions = function(options) {
Expand Down Expand Up @@ -130,6 +131,16 @@ Provider.prototype.send = function(payload, callback) {
}
};

Provider.prototype.on = function(eventName, listener) {
if (eventName === "data") {
const maxListeners = this.getMaxListeners();
if (this.listenerCount(eventName) + 1 > maxListeners) {
this.setMaxListeners(maxListeners + 1);
}
}
this.oldOn(eventName, listener);
};

Provider.prototype.close = function(callback) {
// This is a little gross reaching, but...
this.manager.state.stopMining();
Expand Down