INNER CODE UNIT · TypeScript
mapWithConcurrency
Core-Mate/OpenGUI · deepseek-harness-plugin/src/index.ts:280
export async function mapWithConcurrency<Input, Output>(
values: readonly Input[],
limit: number,
signal: AbortSignal,
worker: (value: Input, index: number, signal: AbortSignal) => Promise<Output>,
): Promise<Output[]> {
const output = new Array<Output>(values.length)
const batch = new AbortController()
const combined = AbortSignal.any([signal, batch.signal])
let next = 0
const runWorker = async (): Promise<void> => {
while (true) {
if (combined.aborted) throw combined.reason
const index = next++
if (index >= values.length) return
try {
output[index] = await worker(values[index]!, index, combined)
} catch (error) {