I'm developing a web app, which user could post a thread, 2 steps for this: one is to save the thread to thread collection, one is to save the threadID to user collection.
However, after saving to the thread collection, I wanna send the response immediately without waiting for the other saving action to finish.
Is there any recommend solution for this by using the express.js or node itself without using the other task queue sort of libs?
Could I just trigger an event then send the response? Will the event listener continue to run regardless the request is already fulfilled?
Thanks
You can send the response after the creation of the thread and before user data update for threadID.
Below is pseudo code for the same:
var express = require('express');
var app = express();
app.post('/', function(req, res, next) {
threadCreationRequest(function(err, data) {
res.send(data);
userUpdateRequest();
});
}