Повторите Async Call N Times в JS
const repeatCall = (call, {
repeat = 1,
params = []
}) => {
const calls = [];
for (let i = 0; i < repeat; i++) {
calls.push(call(...params));
}
return calls;
}
const asyncFunc = async (param1, param2) => {
return await something();
}
Promise.all(
repeatCall(
asyncFunc,
{
repeat: 10, // repeat call ten times
params: [param1Value, param2Value],
}
))
.then((responses) => {
// do something with array of 10 responses
})
Anxious Alligator