Answer the question
In order to leave comments, you need to log in
Node js calling an async function in a loop. How to wait for data?
There are two tables at one time at another event.
First I make a selection from the time table, then I need to select the corresponding events from the event table. I am making a loop using an asynchronous function to select the result at the end of the loop I have no data yet, tell me what should I do in this situation?
Answer the question
In order to leave comments, you need to log in
Or you add a counter and in each callback (to which data comes) you add it and check if this is the last piece of data. Or use the async library: https://github.com/caolan/async namely async.each or async.parallel.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question