V
V
vizaville2015-03-26 14:45:44
Node.js
vizaville, 2015-03-26 14:45:44

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

2 answer(s)
Y
Yuri Shikanov, 2015-03-26
@dizballanze

Use the map method of the async module .

T
Timur Shemsedinov, 2015-03-26
@MarcusAurelius

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 question

Ask a Question

731 491 924 answers to any question