Home > OS >  Nodejs - Return response while sql is running
Nodejs - Return response while sql is running

Time:12-02

I have a function that simply invokes another function that executes sql and returns a uuid. The idea is that - the sql is a long running task, and instead of making the user wait until the sql execution takes place, id like to send a uuid, with which they can make a subsequent request to fetch the results. Here is my code:

async getUUID() {
 await executeSql();
 let uuid = uuidv4();//being created using the library
 return uuid;
}

async executeSql() {
 //sql query stuff
}

However, I get the uuid only when the sql execution is complete. How can I make this more independent of the executeSql function?

CodePudding user response:

async getUUID() {
 executeSql();
 let uuid = uuidv4();//being created using the library
 return uuid;
}

await will wait for the promise return. If you do not want to wait, just delete it. So It will run in asynchronous mode.

  • Related