Fix this TypeScript function with the smallest reasonable pa...
Prompt
Fix this TypeScript function with the smallest reasonable patch. Requirements: 1. Run at most 3 tasks concurrently. 2. Return results in the same order as the input. 3. If any task fails, stop starting new tasks and reject with that error. 4. Tasks already running may finish. 5. Each item may run at most once. 6. Do not use external libraries or redesign the API. async function processAll<T, R>( items: T[], worker: (item: T) => Promise<R> ): Promise<R[]> { const results: R[] = []; async function run() { while (items.length) { const item = items.shift()!; const result = await worker(item); results.push(result); } } await Promise.all([run(), run(), run()]); return results; } Return: 1. The corrected code. 2. A short explanation of what was wrong. 3. Three tests that demonstrate your solution is correct. Do not add features that were not requested.