-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(app): fix referral query of volume (#982)
- Loading branch information
Showing
4 changed files
with
70 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export async function limitConcurrency<T, R>( | ||
tasks: T[], | ||
handler: (task: T) => Promise<R>, | ||
limit: number | ||
): Promise<R[]> { | ||
const results: R[] = [] | ||
const taskQueue: T[] = [...tasks] | ||
|
||
const executeTask = async () => { | ||
if (taskQueue.length === 0) return | ||
|
||
const task = taskQueue.pop() | ||
if (task !== undefined) { | ||
const result = await handler(task) | ||
results.push(result) | ||
} | ||
|
||
await executeTask() | ||
} | ||
|
||
const initialPromises = Array.from({ length: limit }).map(() => executeTask()) | ||
await Promise.all(initialPromises) | ||
|
||
return results | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters