/** Map one item at a time, preserving order and stopping before the next operation on failure. * Use for dependent mutations or to cap GitHub requests and file handles at one in flight. */ export async function mapSequentially( items: Iterable, operation: (item: Input, index: number) => Promise, ): Promise { const results: Output[] = []; for await (const result of sequentialResults(items, operation)) results.push(result); return results; } async function* sequentialResults( items: Iterable, operation: (item: Input, index: number) => Promise, ): AsyncGenerator> { let index = 0; for (const item of items) yield operation(item, index++); }