Is there any way to limit the number of concurrent Q promises to be executed at once in node js?
I am building a web scraper , which must request and parse more 3000+ pages and without throttle some of the requests i make aren't responded to on time, so the connection rests and the needed response (html code) becomes unavailable.
To counter act this, i found that limiting the number of requests my problem goes away.
I have tried the following methods but to no avail:
- Concurrency limit in Q promises - node
- How can I limit Q promise concurrency?
- https://gist.github.com/gaearon/7930162
- https://github.com/ForbesLindesay/throat
I need to request an array of urls, doing only 1 request at a time and when all urls in the array have completed, then return the results in a array.
function processWebsite() {
//computed by this stage
urls = [u1,u2,u3,u4,l5,u6,u7,u8,u9];
var promises = throttle(urls,1,myfunction);
// myfunction returns a Q promise and takes a considerable
// amount of time to resolve (approximately 2-5 minutes)
Q.all(promises).then(function(results){
//work with the results of the promises array
});
}