Advertisement
Guest User

Untitled

a guest
May 27th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const create = (request) => {
  2.     return axios.post(link, body)
  3. //  ^^^^^^--- return the chain
  4.         .then((response) => Promise.all( // Wait for all promises we're about to create to resolve
  5.            arr.map(obj => new Promise((resolve, reject) => { // What is `arr`?
  6.                 const file = fs.createWriteStream("./downloads/" + obj.name);
  7.                 https.get(obj.download_url, response => {
  8.                      let stream = response.pipe(file);
  9.                      stream
  10.                          .on("finish", () => {
  11.                              resolve(); // Resolve this download's result
  12.                          })
  13.                          .on(/*...presumably there's an error callbac*/, () => {
  14.                              reject();
  15.                          });
  16.                 });
  17.             }));
  18.         )
  19.         .then(() => "Hi...."); // Final overall result
  20. // Don't catch errors, leave that to the caller
  21. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement