Skip to content

Instantly share code, notes, and snippets.

@bmeck
Created August 12, 2010 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmeck/521518 to your computer and use it in GitHub Desktop.
Save bmeck/521518 to your computer and use it in GitHub Desktop.
var EventEmitter = require( "events" ).EventEmitter
, oldOn = EventEmitter.prototype.addListener
, id = 0
module.exports = { }
EventEmitter.prototype.addListener = EventEmitter.prototype.on = function on(evt,cb) {
var capsule = {
source:this
, callback: cb
, event: evt
}
, myId = id++
outstanding[ myId ] = capsule
return oldOn( evt,function callback( ) {
cb.apply( this, arguments )
delete outstanding[ myId ]
} )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment