Sunday, 2 April 2017

Bluebird Promise.all doesn't get called

I have a url which returns a list of other urls For each url, I want to do stuff and then use Promise.all to tell me that it finished.

For some reason, it does process all urls, but the Promise.all doesn't seem to be called (Bluebird)

What am I doing wrong?

```

var rp = require("request-promise");

var promrequests = [];
rp(
 {
  url: url_of_list_of_urls,
  json: true,
 },
 function(error, response, body) {
  if (!error && response.statusCode === 200) {
   let urls = [];
   for (var i in body) {
    urls.push(body[i]);
   }

   for (let j in urls) {
    let url = urls[j];

    promrequests.push(
     rp(
      { url: url, followAllRedirects: true },
      function(error, response, body) {
       console.log("working on " + url);
       // do stuff
      }
     )
    );
   }

   Promise.all(promrequests).then(function() {
    console.log("finished all");
   });
  }
 }
);
```



via Nick Ginanto

No comments:

Post a Comment