Answer the question
In order to leave comments, you need to log in
Promise.allSettled hangs with a large number of promises, what should I do?
Good afternoon.
There is a certain code that receives data through the API of a third-party service. But after several executions, there are hangups when receiving data, respectively, falls off by timeout.
If you manually follow the link on which it hangs, then everything works out properly.
It also works properly on a small number of requests, but as the number goes over about 300-400, then sometimes freezes begin.
How to get rid of freezes and get full data?
let result = await Promise.allSettled(promises);
return result
.filter((p) => {
console.log(p);
return p.status === 'fulfilled' && p.value.stringencyData !== undefined;
})
.map((e) => {
const { stringencyData } = e.value;
return {
dateValue: stringencyData.date_value,
countryCode: stringencyData.country_code,
stringencyActual: stringencyData.stringency_actual,
...stringencyData,
};
});
async function getData(alpha, date) {
let res, json;
try {
res = await fetch(`https://covidtrackerapi.bsg.ox.ac.uk/api/v2/stringency/actions/${alpha}/${date}`, {
timeout: 200000,
});
} catch (err) {
console.log(err);
}
try {
json = await res.json();
} catch (err) {
console.log(err);
}
return json;
}
Answer the question
In order to leave comments, you need to log in
let it be
this is the restriction of requests from the server side (anti ddos).
https://qna.habr.com/q/1105356 here is the way.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question