workflows/concurrent

Source: src/workflows/concurrent.ts

Running several things at once, but not all of them: a subtask is a session, and N sessions opening together is the bill nobody meant to pay.

mapConcurrent

function

export async function mapConcurrent<T, R>(
	items: readonly T[],
	concurrency: number,
	run: (item: T, index: number) => Promise<R>,
): Promise<R[]> { /* … */ }

Runs run over items with at most concurrency in flight, in index order.

A bounded worker pool, not a Promise.all: N subtasks must not open N sessions at once. Results come back in the order of items, whatever the order they finished in - a caller reading results[2] means the third task, always.

run is expected to handle its own failures; a rejection here rejects the whole map, which is why every combinator hands it a function that returns a failed Result instead of throwing.