Questions about the use of js async

originally wrote JAVA, but the sophomore
recently encountered asynchronous programming in the new nodejs, is a bit difficult to understand.

now I am writing a crawler originally done in JAVA, get a url list, submit the request crawl web page with for loop, and then insert several records into the database through for loop after processing.

it seems that the for loop is understood by Synchronize. After the loop is finished, the request asynchronously sends out the request and will not wait, and then the sequelize will not wait.

then finally I want to log a message after all asynchronous processing. These two-level asynchronous operations don"t know how to handle them.

how to wait for all asynchronous operations to finish executing the next command

UPDAT 4Compact 23 1purl 20:

clipboard.png

forpromiseAll

4/23 1:41

clipboard.png

the question is whether there are more elegant ways that async and await cannot be used in this case, or do I not think of it


promise.all is already the easiest way. Everything else needs to be done manually complete this logic


this is the final adjusted answer. But I still want to ask if there is a more Synchronize way of writing without having to save it in an array every time?
clipboard.png

Menu