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

Events instead of log function #55

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

Events instead of log function #55

gagle opened this issue Nov 7, 2012 · 2 comments
Labels
Milestone

Comments

@gagle
Copy link

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){
  ...
});
@sandfox
Copy link
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
Copy link
Collaborator

sandfox commented Nov 26, 2016

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

@sandfox sandfox closed this as completed Nov 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants