I'd like to request one page after another, the following code seems request all the pages in the same time, is there a way to fetch one page after the previous one is done? thanks
var Promise = require("bluebird");
var request = Promise.promisifyAll(require('request'));
var URLS = ["http://sample.com/j1", "http://sample.com/j2"]
Promise.map(URLS, function (item) {
return request.postAsync({url: item}).spread(function (response,body) {
var items = JSON.parse(body)
return items
})
}).then(function (r) {
console.log(r.length)
})
You can set the concurrency level, which is specific to bluebird.
This will issue all the promises one at a time.