I have piece of code here where I have used Promises to make use the a timeout function resolves after 1 min if the reload function takes more than 1 min to execute, the problem I am facing is the code is entering the promise declarations initially and executing everything internally one by one. (Its hitting setTimeout first and later reload() and then finally promise.race). It should actually hit promise.race first and execute 2 promises simultaneously later. How to refactor this.
async function test() {
const timerPromise = new Promise((resolve, reject) => {
setTimeout(resolve, 60000, "Done"); //
});
const promise = new Promise((resolve, reject) => {
reload(); //
resolve("Successfull");
});
const response = Promise.race([timerPromise, promise]).then((x) => {
console.log(response)
});
}
Thanks
It should actually first just initialize the const and then hit promise.race and execute 2 promises simultaneously later.
Sourabh Raja is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.