L
L
lavezzi12018-03-09 09:40:34
JavaScript
lavezzi1, 2018-03-09 09:40:34

How to determine that all asynchronous operations have completed?

Hello.
There is an async method in which, first, for an array of data, a get request is made for each element of this array, then it resolves

const responses = await Promise.all(responsePromises);

Next, you need to go through the responses and pull the post request:
items.forEach((item, itemIndex) => {
          responses.forEach((res, resindex) => {
            if (itemIndex === resIndex) {
              axios.post(res.post_url, item, config);
            }
          });
        });

At the end of all these posts, you need to throw out a notification. How to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-03-09
@lavezzi1

What prevents to apply Promise.all once again? Instead of nested forEach's, it will be something like this:

Promise.all(items.map((item, index) => axios.post(responses[index], item, config)))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question