Написал более универсальную версию кода
Код:
async function callFuncForArray<V, K>(items: V[], func: (item: V) => Promise<K>): Promise<K[]> {
let promises: Promise<K>[] = [];
const responses: K[] = [];
for (let item of items) {
promises.push(func(item));
if (promises.length >= 30) {
const res = await Promise.all(promises);
responses.push(...res);
promises = []
}
};
if (promises.length > 0) {
const res = await Promise.all(promises);
responses.push(...res);
}
return responses;
}
Пример применения:
Код:
const updated_items = await callFuncForArray(items, async current_item => {
current_item.data.storage = "Test";
await current_item.save();
await current_item.setStatus(current_item.fields.__status.variants.archive);
return current_item;
})