fix(): Index integration tests flackyness (#13953)
* fix(): Index integration tests flackyness * fix * Create twenty-eels-remain.md * fix * fix * fix * fix * finalize * finalize * finalize * finalize * finalize * finalize * chore: empty commit * finalize * finalize * chore: empty commit * finalize * finalize
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { promiseAll } from "./promise-all"
|
||||
|
||||
/**
|
||||
* Execute functions with a concurrency limit
|
||||
* @param functions Array of functions to execute in parallel
|
||||
@@ -7,13 +9,12 @@ export async function executeWithConcurrency<T>(
|
||||
functions: (() => Promise<T>)[],
|
||||
concurrency: number
|
||||
): Promise<PromiseSettledResult<Awaited<T>>[]> {
|
||||
const results: PromiseSettledResult<Awaited<T>>[] = new Array(
|
||||
functions.length
|
||||
)
|
||||
const functionsLength = functions.length
|
||||
const results: PromiseSettledResult<Awaited<T>>[] = new Array(functionsLength)
|
||||
let currentIndex = 0
|
||||
|
||||
const executeNext = async (): Promise<void> => {
|
||||
while (currentIndex < functions.length) {
|
||||
while (currentIndex < functionsLength) {
|
||||
const index = currentIndex++
|
||||
const result = await Promise.allSettled([functions[index]()])
|
||||
results[index] = result[0]
|
||||
@@ -21,11 +22,11 @@ export async function executeWithConcurrency<T>(
|
||||
}
|
||||
|
||||
const workers: Promise<void>[] = []
|
||||
for (let i = 0; i < concurrency; i++) {
|
||||
for (let i = 0; i < Math.min(concurrency, functionsLength); i++) {
|
||||
workers.push(executeNext())
|
||||
}
|
||||
|
||||
await Promise.all(workers)
|
||||
await promiseAll(workers)
|
||||
|
||||
return results
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user