Created
August 30, 2014 18:45
-
-
Save myndzi/3fe3b18cc6f542f36956 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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