var blocked = {};
app.get('/bla', function(req, res){
var id = getIdFromRequest(req);
if (blocked[id]) // if true then another request is being served
return res.send('Concurrent requests not allowed');
blocked[id] = true;
// do your thing here
// and respond
res.send('some data');
// unlock the user
delete blocked[id];
});
1 回答
有很多方法可以实现这一点,但我能想到的最简单的方法是: