While waiting for a response from express.js in the code below, Angular keeps waiting even though other GET requests have been completed and does not draw the relevant HTML at all.
Is there a way to avoid waiting for the following request response?
I checked this question , but it didn't work for me.
Angular:
ngOnInit() {
this.requestToServer();
}
requestToServer():void{
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json'
})
};
const body = null;
const url = `dummy`;
this.http.post(url, body, httpOptions).subscribe();
}
Express.js:
app.post('/dummy', function (req, res, next) {
// Even if you return this response to a client here, the subsequent process will continue.
res.status(200).json({
completed: true
});
// Testing : I don't want Angular to wait here.
sleep(5000);
// A process with no response. (e.g.) db update query
// ...
});
function sleep(waitMsec) {
var startMsec = new Date();
while (new Date() - startMsec < waitMsec);
}