Skip to content

Instantly share code, notes, and snippets.

@fiveisprime
Last active August 29, 2015 14:11
Show Gist options
  • Select an option

  • Save fiveisprime/fcfeba7d82ec236e5fdc to your computer and use it in GitHub Desktop.

Select an option

Save fiveisprime/fcfeba7d82ec236e5fdc to your computer and use it in GitHub Desktop.
Async for loops in JavaScript
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