Skip to content

Instantly share code, notes, and snippets.

@dokipen
Created June 23, 2012 14:44
Show Gist options
  • Select an option

  • Save dokipen/2978541 to your computer and use it in GitHub Desktop.

Select an option

Save dokipen/2978541 to your computer and use it in GitHub Desktop.
promises with step
// Module Dependencies
var step = require('step')
, request = require('request')
, inspect = require('util').inspect
// Some URLs to play with, and a queue to keep the code readable
, urls = ['google.com', 'twitter.com', 'facebook.com']
step
( function() {
var self = this
// For each url, create a parallel step
urls.forEach(function(url) {
request({url: 'http://'+url}, self.parallel()) } ) }
, function(err) {
var results = Array.prototype.slice.call(arguments, 1)
// handle errors
if (err) {
console.log("rejected "+err) }
// print results
console.log("fulfilled "+results.map(function(r){return inspect(r.headers)}))
// eh, we're done
console.log("finally") } )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment