I am using Express.js to initiate a computationally expensive task. I want to immediately respond to the request with an acknowledgement so the client knows the server has started working. Once the expensive task has finished, I want the server to tell the client the result of the process.
The only solution I've thought of is the client's request could include a URL for me to POST the answer. Upon POST'ing, the client could pick up the answer and use it appropriately; however, I am skeptical that this is the best approach. Is there a common idiom for handling cases like this?
Consider the following snippet. How would I send an answer to the client?
app.get("/getMeaningOfLife/", function(req, rsp) {
rsp.send("Working on it now!");
// This is expected to take a long time, but eventually returns "42"
var meaningOfLife = computeMeaningOfLife();
// send answer to client here
// HOW DO I DO THIS?
});