Skip to content

Instantly share code, notes, and snippets.

@myndzi
Created August 30, 2014 18:45
Show Gist options
  • Save myndzi/3fe3b18cc6f542f36956 to your computer and use it in GitHub Desktop.
Save myndzi/3fe3b18cc6f542f36956 to your computer and use it in GitHub Desktop.
function Thing(socket) {
this.socket = socket;
this.socket.once('end', this.cleanup.bind(this));
this.handlers = [ ];
}
Thing.prototype.onDisconnect = function (cb) {
this.handlers.push(cb);
}
Thing.prototype.cleanup = function () {
return Promise.reduce(this.handlers, function (retVal, handler) {
return handler(retVal);
}, 'initialValue')
.then(function (finalValue) {
// do whatever you want
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment