Skip to content

Commit a63ca8f

Browse files
author
Ioan Moldovan
committed
fix: limit
1 parent ec27373 commit a63ca8f

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

extension/chrome/settings/inbox/inbox-modules/inbox-list-threads-module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class InboxListThreadsModule extends ViewModule<InboxView> {
2020
if (threads?.length) {
2121
await promiseAllWithLimit(
2222
10,
23-
threads.map(t => this.renderInboxItem(t.id))
23+
threads.map(t => () => this.renderInboxItem(t.id))
2424
);
2525
} else {
2626
Xss.sanitizeRender('.threads', `<p>No encrypted messages in ${Xss.escape(labelId)} yet. ${Ui.retryLink()}</p>`);

extension/js/common/api/email-provider/gmail/gmail.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export class Gmail extends EmailProviderApi implements EmailProviderInterface {
138138
public msgsGet = async (msgIds: string[], format: GmailResponseFormat): Promise<GmailRes.GmailMsg[]> => {
139139
return await promiseAllWithLimit(
140140
10,
141-
msgIds.map(id => this.msgGet(id, format))
141+
msgIds.map(id => () => this.msgGet(id, format))
142142
);
143143
};
144144

extension/js/common/core/common.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -523,13 +523,14 @@ export const checkValidURL = (url: string): boolean => {
523523
* Resolves when all promises are resolved or rejects when any promise is rejected.
524524
*
525525
* @param concurrency - The maximum number of promises to run at the same time.
526-
* @param tasks - An array of promises.
526+
* @param tasks - An array of functions that return promises.
527527
* @returns A Promise that resolves to an array of the resolved values of the input promises.
528528
*/
529-
export const promiseAllWithLimit = async <V>(concurrency: number, tasks: Promise<V>[]): Promise<V[]> => {
529+
export const promiseAllWithLimit = async <V>(concurrency: number, tasks: (() => Promise<V>)[]): Promise<V[]> => {
530530
let results: V[] = [];
531531
while (tasks.length) {
532-
results = results.concat(await Promise.all(tasks.splice(0, concurrency)));
532+
const currentTasks = tasks.splice(0, concurrency).map(task => task());
533+
results = results.concat(await Promise.all(currentTasks));
533534
}
534535
return results;
535536
};

0 commit comments

Comments
 (0)