Skip to content

Instantly share code, notes, and snippets.

@ben-bradley
Last active August 29, 2015 14:04
Show Gist options
  • Save ben-bradley/88d3b672d3a61660ea2e to your computer and use it in GitHub Desktop.
Save ben-bradley/88d3b672d3a61660ea2e to your computer and use it in GitHub Desktop.
$when for node
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