javascript - Limit number of parallel http requests in node js -
javascript - Limit number of parallel http requests in node js -
hi guys i'm new in node js.
i have script start several http requests within loop let's have create 1000 http requests. thing can 1 http request per ip , have 10 ips
so, after 10 parallel requests have wait response create one.
how wait without block script 1 response http request start one?
my problem if execute while waiting free ip whole script blocked , not receive response.
thanks.
use async module this.
you can utilize async#eachlimit
limit concurrent requests 10.
var urls = [ // list of 100 urls ]; function makerequest(url, callback) { /* create http request */ callback(); // when done, callback } async.eachlimit(urls, 10, makerequest, function(err) { if(err) throw err; });
this code loop through list of urls , phone call makerequest
each one. stop @ 10 concurrent requests , not proceed 11th request until 1 of first 10 have finished.
javascript node.js
Comments
Post a Comment