Skip to content

Instantly share code, notes, and snippets.

@joshperry
Last active August 29, 2015 14:11
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 joshperry/9e3e35e10094746ecb0a to your computer and use it in GitHub Desktop.
Save joshperry/9e3e35e10094746ecb0a to your computer and use it in GitHub Desktop.
Pumping an event stream using Promises
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