J
J
jtag2018-02-15 03:32:44
Node.js
jtag, 2018-02-15 03:32:44

Is it possible to send asynchronous requests in a loop?

rows.forEach(function(row, i, arr){
     connection.query("INSERT INTO ....+ row +   " , function(err) {     
           if(err) console.log(err);
     });
})

How can I track when all requests in a loop will be completed?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vladimir Skibin, 2018-02-15
@msa6886

1. Yes, you can do it
2. Wrap asynchrony in promises and then catch from all

A
Anatoly Zharov, 2018-02-15
@SeaBreeze876

Can. Your example is quite working.

M
Mikhail, 2018-02-15
@mak_ufo

Yes. Your example does just that.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question