1 import runInQueue from '@proton/shared/lib/helpers/runInQueue';
3 export const DEFAULT_PARALLEL_CALL_LIMIT = 5;
5 export function createAsyncQueue<T>(parallelCallLimit: number = DEFAULT_PARALLEL_CALL_LIMIT) {
6 const queue: (() => Promise<T>)[] = [];
10 if (queue.length === 0 || currentLoad >= parallelCallLimit) {
15 const nextTask = queue.shift();
18 .catch((e: Error) => {
27 const addToQueue = (task: () => Promise<T>) => {
32 const clearQueue = () => {
42 export function runInQueueAbortable<T extends () => Promise<R>, R>(
44 parallelCallLimit: number = DEFAULT_PARALLEL_CALL_LIMIT,
47 const result = runInQueue(tasks, parallelCallLimit);
49 signal?.addEventListener('abort', () => {