I want to repeat the operation getRunDetailsStaus()
until the status is done.
So I put the condition in .then()
handler, and I called recursive the funtion next() until the status is DONE.
getStatus(runDetailsId)
is a promise function that returns the status from mongoDB
See below my step definition:
When('the user waits until receive the status DONE',
let start = Date.now()
function getRunDetailsStaus() {
return getStatus(runDetailsId) //promise function and returns the status from mongoDB
}
function next() {
return getRunDetailsStaus().then(function (result) {
console.log("status: ", result.runStatus, Date.now() - start)
if (status == 'DONE') {
return status
}
else {
return next()
}
})
}
return next()
.then((response) => {
// process final results
})
.catch((error) => {
//process error
})
});```
But I get the following error:
function timed out, ensure the promise resolves within 5000 milliseconds
How should I resolve this issue in case the status done in mongo is set in ~30 min?