2 * Executes functions sequentially, at most `maxProcessing` functions at once.
4 async function runInQueue<T>(functions: (() => Promise<T>)[], maxProcessing = 1): Promise<T[]> {
5 const results: T[] = [];
8 const runNext = async (): Promise<any> => {
9 const index = resultIndex;
10 const executor = functions[index];
14 return executor().then((result) => {
15 results[index] = result;
19 return Promise.resolve();
22 const promises: Promise<any>[] = [];
23 for (let i = 0; i < maxProcessing; i++) {
24 promises.push(runNext());
26 await Promise.all(promises);
30 export default runInQueue;