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

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e943f5-14bd.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e943f5-14bd.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?