boomchickawawa
boomchickawawa

Reputation: 556

Nodejs - Return response while sql is running

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?

Upvotes: 0

Views: 54

Answers (1)

ElapsedSoul
ElapsedSoul

Reputation: 825

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.

Upvotes: 1

Related Questions