Last active
August 29, 2015 14:04
-
-
Save ben-bradley/88d3b672d3a61660ea2e to your computer and use it in GitHub Desktop.
$when for node
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
var when = requrie('when'), | |
request = require('request'); | |
var getAll = when.all([ | |
promisedRequest({ url: 'http://google.com' }), | |
promisedRequest('http://yahoo.com'), | |
promisedRequest('https://foo.bar') | |
]); | |
function promisedRequest(options) { | |
return when.promise(function(resolve, reject, notify) { | |
request.apply(this, [options, function(err, res, body) { | |
if (err) | |
return reject(err); | |
return resolve(body); | |
}]); | |
}); | |
} | |
getAll.then(function(results) { | |
console.log(results); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment