Asynchronous operations in node loops

async en_exec_list ()
    {
        
        console.log("************************************************")
        
        //   //ID
          var sql = "SELECT * FROM en_del_products WHERE  STATE = 0 limit 1";
          var waitList = await mysql_auto_db.await_query(sql);
        
          for( let doc of waitList)
          {
              let c= await ftp_db.await_query({
                action: "delete",
                offlinePath: "www/1.txt"
            });
            console.log(c)
          }

          console.log("************************************************")

    }

Hello, what can I do to wait for the end of the for execution before the end of the print run?

ftp_db.await_query is self-encapsulated and used to delete files in FTP.

current error message:

clipboard.png

Mar.02,2022

error report means that ftp_db.await_query executes an error but you don't catch it. The asynchronous order of the code you write should be fine


every promise in the loop is placed in an array, and the promise.all.then ends at the end of the print run


The methods of

await are all placed under Promise.all, and then the print run ends in the callback then.

because await is executed asynchronously in your code, console, will be executed first and then the methods that follow await will be executed.

at the same time, because there is no relationship between them, whoever returns first ends first.

Menu