0

I need to handle requests one-by-one in javascript.

For example, we have 10 simultanious POST requests to the route /wall/createPost and following code:

app.post('/wall/createPost', (request, response) => {
    ...
    queue.push(request);
    ... somehow await to solve this and after make response.send('ok') ...
});

I need to make some queue to handle simillar tasks one-by-one. For example, loop.

let queue = [];

setInterval(() => {
    const dataToHandle = queue[0];
    ...
    queue.shift();
}, 1000);

How to await solvation of the task inside app.post callback?

user14080657
  • 108
  • 11
  • 1
    could you write your code you have at the moment? i still have no idea what you want achieve – bill.gates Dec 10 '20 at 13:59
  • feels like a for..in loop is the right candidate to block each async request..but yea, not too sure what you're going after. – LostJon Dec 10 '20 at 14:06
  • @LostJon yes, I need just this. How to make it in code, could you please explain? – user14080657 Dec 10 '20 at 14:14
  • 1
    You'll want to [queue the tasks](https://stackoverflow.com/q/64955564/1048572). That doesn't mean you have to process them with `setInterval` – Bergi Dec 10 '20 at 14:44

0 Answers0