chore(modules-sdk): parallel migrations (#13898)

This commit is contained in:
Carlos R. L. Rodrigues
2025-10-31 11:05:53 -03:00
committed by GitHub
parent fffc1be1e7
commit 13d7d15be5
14 changed files with 124 additions and 24 deletions

View File

@@ -0,0 +1,31 @@
/**
* Execute functions with a concurrency limit
* @param functions Array of functions to execute in parallel
* @param concurrency Maximum number of concurrent executions
*/
export async function executeWithConcurrency<T>(
functions: (() => Promise<T>)[],
concurrency: number
): Promise<PromiseSettledResult<Awaited<T>>[]> {
const results: PromiseSettledResult<Awaited<T>>[] = new Array(
functions.length
)
let currentIndex = 0
const executeNext = async (): Promise<void> => {
while (currentIndex < functions.length) {
const index = currentIndex++
const result = await Promise.allSettled([functions[index]()])
results[index] = result[0]
}
}
const workers: Promise<void>[] = []
for (let i = 0; i < concurrency; i++) {
workers.push(executeNext())
}
await Promise.all(workers)
return results
}

View File

@@ -19,6 +19,7 @@ export * from "./define-file-config"
export * from "./dynamic-import"
export * from "./env-editor"
export * from "./errors"
export * from "./execute-with-concurrency"
export * from "./file-system"
export * from "./filter-object-by-keys"
export * from "./filter-operator-map"