Events instead of log function #55

Closed
gagle opened this Issue Nov 7, 2012 · 2 comments

Comments

Projects
None yet
2 participants

gagle commented Nov 7, 2012

Hi,

I'd like to log my own custom errors. Also, I don't want to log every second the message "availableObjects.length=x". Can you inherite the pool from EventEmitter and just emit events so we can catch them and do whatever we want? It's a very easy modification. Just replace this line when you export the module:

var me = {},

By this:

var Pool = function (){
  events.EventEmitter.call (this);
};
Pool.prototype = Object.create (events.EventEmitter.prototype);
Pool.prototype.constructor = Pool;
var me = new Pool (),

You must add the events module:

var events = require ("events");

Then, instead of calling the log function you can throw an event with the data. For example, the createResource function:

me.emit ("create-resource", count, factory.min, factory.max);

And to catch it from outside your library:

pool.on ("create-resource", function (count, min, max){
  ...
});
Collaborator

sandfox commented Jun 20, 2014

Very down with this idea in general. Have a couple of questions though.
Would we continue to also support log at the same time?
For error events, should we only emit if we have a listener? (if we emit regardless and there is no listener then we will blow things up for the user).

I can see this either being a something to bump the major version for (so we can go crazy and change behaviour) or being conservative changes and just a minor version bump.

Thoughts?

@sandfox sandfox added this to the V3.0.0 milestone Jul 5, 2014

@sandfox sandfox added the feature label Oct 10, 2014

@sandfox sandfox modified the milestones: v3.next, V3.0.0 Oct 30, 2016

Collaborator

sandfox commented Nov 26, 2016

Going to close for now until a more concrete proposal or impl comes along.

@sandfox sandfox closed this Nov 26, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment