Last active
August 29, 2015 14:11
-
-
Save joshperry/9e3e35e10094746ecb0a to your computer and use it in GitHub Desktop.
Pumping an event stream using Promises
This file contains 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
var network = getNetworkSystem(); | |
var io = initWebsockets(); | |
var waitForNodes = function(reject) { | |
return network.onNodeIdentification() | |
.then(function(nodeId) { | |
io.emit('node found', nodeId); | |
}, reject) | |
.then(waitForNodes.bind(this, reject)); | |
}; | |
var valPromise = Promise(function(resolve, reject) { | |
waitForNodes(reject); | |
}) | |
.then( | |
function() {}, | |
function(err) { | |
console.error(err); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment