I've seen something like this asked many times, but I never see a clear answer given.
Given an express server with a block like this:
var express = require('express');
var router = express.Router();
app.use(async function(req, res, next){
console.log("REQUEST DETECTED");
await new Promise(r => setTimeout(r, 5000));
next();
});
app.use('/', router.get('/', function(req, res, next) {
// Serve a basic page
});
Consider this timeline
What I expected would be
Can Express not capitalize on time spent awaiting in order to process other requests? And just to be clear, the same thing happens when I await useful work like running a DB query. If one user requests a heavy query, the entire site hangs for every other user. Is there an alternative solution here?