不要怂,就是干,撸起袖子干!

Commit 3d8bce57 by Michael Weibel

Remove setTimeout in favor of process.nextTick()

According to [process.nextTick() documentation](http://nodejs.org/api/process.html#process_process_nexttick_callback), using setTimeout is not recommended:

    On the next loop around the event loop call this callback. This is not a simple alias to setTimeout(fn, 0), it's much more efficient.

I'm not sure why you didn't use `nextTick()` yet, so if it was intended, please close :)
I'm currently testing this change and it seems to work better than with setTimeout.

What I'm unsure is the run function - it's not needed anymore imho.
1 parent 477289e6
Showing with 7 additions and 7 deletions
...@@ -3,18 +3,18 @@ var util = require("util") ...@@ -3,18 +3,18 @@ var util = require("util")
module.exports = (function() { module.exports = (function() {
var CustomEventEmitter = function(fct) { var CustomEventEmitter = function(fct) {
this.fct = fct this.fct = fct;
var self = this;
process.nextTick(function() {
if (self.fct) {
self.fct.call(self, self)
}
}.bind(this));
} }
util.inherits(CustomEventEmitter, EventEmitter) util.inherits(CustomEventEmitter, EventEmitter)
CustomEventEmitter.prototype.run = function() { CustomEventEmitter.prototype.run = function() {
var self = this var self = this
// delay the function call and return the emitter
setTimeout(function(){
self.fct.call(self, self)
}, 1)
return this return this
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!