diff --git a/extension/chrome/settings/inbox/inbox-modules/inbox-list-threads-module.ts b/extension/chrome/settings/inbox/inbox-modules/inbox-list-threads-module.ts index b0caf05d6fd..959e4c7e978 100644 --- a/extension/chrome/settings/inbox/inbox-modules/inbox-list-threads-module.ts +++ b/extension/chrome/settings/inbox/inbox-modules/inbox-list-threads-module.ts @@ -20,7 +20,7 @@ export class InboxListThreadsModule extends ViewModule { if (threads?.length) { await promiseAllWithLimit( 10, - threads.map(t => this.renderInboxItem(t.id)) + threads.map(t => () => this.renderInboxItem(t.id)) ); } else { Xss.sanitizeRender('.threads', `

No encrypted messages in ${Xss.escape(labelId)} yet. ${Ui.retryLink()}

`); diff --git a/extension/js/common/api/email-provider/gmail/gmail.ts b/extension/js/common/api/email-provider/gmail/gmail.ts index 96ca8634876..a961d482124 100644 --- a/extension/js/common/api/email-provider/gmail/gmail.ts +++ b/extension/js/common/api/email-provider/gmail/gmail.ts @@ -138,7 +138,7 @@ export class Gmail extends EmailProviderApi implements EmailProviderInterface { public msgsGet = async (msgIds: string[], format: GmailResponseFormat): Promise => { return await promiseAllWithLimit( 10, - msgIds.map(id => this.msgGet(id, format)) + msgIds.map(id => () => this.msgGet(id, format)) ); }; diff --git a/extension/js/common/core/common.ts b/extension/js/common/core/common.ts index 47bd83af2a1..8c63bcc582d 100644 --- a/extension/js/common/core/common.ts +++ b/extension/js/common/core/common.ts @@ -523,13 +523,14 @@ export const checkValidURL = (url: string): boolean => { * Resolves when all promises are resolved or rejects when any promise is rejected. * * @param concurrency - The maximum number of promises to run at the same time. - * @param tasks - An array of promises. + * @param tasks - An array of functions that return promises. * @returns A Promise that resolves to an array of the resolved values of the input promises. */ -export const promiseAllWithLimit = async (concurrency: number, tasks: Promise[]): Promise => { +export const promiseAllWithLimit = async (concurrency: number, tasks: (() => Promise)[]): Promise => { let results: V[] = []; while (tasks.length) { - results = results.concat(await Promise.all(tasks.splice(0, concurrency))); + const currentTasks = tasks.splice(0, concurrency).map(task => task()); + results = results.concat(await Promise.all(currentTasks)); } return results; };