To make concurrent asynchronous requests in NodeJS (Javascript), we can take advantage of
the setTimeout
function and use it together with async/await
, plus trusty old count
.
What we are aiming for here is that 3 requests get sent asynchronously, but the promise they're contained in only resolves when ALL 3 have returned. If it takes too long, we want to reject the promise, since the data has likely become stale.
Originally I tried using Promise.all()
, but ran into problems with it. The following implementation worked