I have an express application where I have a generator function that needs aprox. 5 minutes for processing a lot of data. Unfortunately I can not optimize that function.
Express automatically times out after 2 minutes and I do not want to alter that only for this specific function. I figured that maybe if I made periodically a res.write()
call, the 2 minute rule does not apply.
My question:
How can I execute a res.write('Something')
every X seconds while waiting for the other function to terminate ?
I want it to do something like the following, I hope you get the idea.
function main() {
co(function* () {
const something = yield promise(); // function that needs a lot of time
const doWhileWaiting = setTimeout(() => {
if (!something) {
// Print this while waiting for the value of something
console.log('Waiting for something ... ');
} else {
console.log(something);
clearInterval(doWhileWaiting);
}
}, 5000);
});
}