Created
June 23, 2012 14:44
-
-
Save dokipen/2978541 to your computer and use it in GitHub Desktop.
promises with step
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
| // 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