In response to a http request to an endpoint I have to basically make some computations, db calls, etc. and return the response to the requester. Out of the computations some of them can be made after the response is being sent and for my case it makes sense to return the response as fast as possible.
From what I've seen in ASP.NET once you return the response the whole request-response cycle is over. Is what I need achievable with basic code without using a job queue system or anything like that? I've looked into using Task and fire an async operation before sending the response back, but from what I've been reading it can be dangerous, the system might terminate the process randomly and such.
I'm very much used to node/express and I'm trying to do the equivalent of:
router.get('/myroute', executeStuff, returnResponse, executeStuff2);
// initial processing
executeStuff = (req, res, next) => {
someAsyncOperation()
.then(() => next())
.catch(...);
}
// send response after necessary stuff is done
returnResponse = (req, res, next) => {
res.send(responseBody);
next();
}
// do the after response processing, side effects, etc.
executeStuff2 = (req, res, next) => {
someAsyncOperation()
.then(() => {
// end of the chain
})
.catch(...);
}