0

SCENARIO:

Below is the code that reflect 2 nested asynchronous call,

const create = (request) => {
    axios.post(link, body)
    .then((response) => {
       arr.forEach(obj => {
            const file = fs.createWriteStream("./downloads/" + obj.name);
            https.get(obj.download_url, response => {
                let stream = response.pipe(file);
                 stream.on("finish", () => {
                    if (i == count) {
                       return "Hi...."
                    }
                    i++;
                });
            });
        });
    })
    .catch((error) => {
        return error;
    });
};

QUESTION:

How can I return "Hi...." back to the user.

Ankur Soni
  • 5,725
  • 5
  • 50
  • 81
  • See in particular the "parallel" parts of [my answer to the linked question](https://stackoverflow.com/a/43766002/157247). – T.J. Crowder May 27 '19 at 12:38
  • I am Still not clear, Could you please solve my question. That would help a lot. – Ankur Soni May 27 '19 at 12:42
  • Your best bet at solving it is to thoroughly read that question and at least a couple of its answers (I'd suggest mine, but...). You cannot have thoroughly read either in four minutes. As it happens, I'd already [done this](https://pastebin.com/4zP4MADk) to point you the right way. The result of calling `create` will be a promise. – T.J. Crowder May 27 '19 at 12:44

0 Answers0