Last active
August 29, 2015 14:11
-
-
Save fiveisprime/fcfeba7d82ec236e5fdc to your computer and use it in GitHub Desktop.
Async for loops in JavaScript
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 request = require('request') | |
| , counter = 0; | |
| !function getResource() { | |
| request('http://thepiratebay.se/torrent/' + counter, function (err, response) { | |
| if (200 === response.statusCode) { | |
| console.log('Found something at http://thepiratebay.se%s', response.req.path); | |
| } | |
| if (counter++ < 10000000) { | |
| // Delay requests by some amount to be nice to TPB's servers. | |
| // ..or just remove the timeout completely. :) | |
| setTimeout(getResource, 100); | |
| } | |
| }); | |
| }(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment