Created
January 9, 2021 01:47
-
-
Save wperron/1066ad43a77a3cd7aeb3bdecfa44d9d1 to your computer and use it in GitHub Desktop.
Example of exception thrown in pooledMap not getting caught
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { pooledMap } from "https://deno.land/[email protected]/async/pool.ts"; | |
async function collectAsyncIterable<T>( | |
iterator: AsyncIterable<T>, | |
): Promise<T[]> { | |
const collected = [] as T[]; | |
for await (const v of iterator) { | |
collected.push(v); | |
} | |
return collected; | |
} | |
const iter = [...Array(100).keys()]; | |
async function cb(i: number): Promise<number> { | |
if (i === 42) throw new Error("can't handle the wisdom"); | |
return i; | |
} | |
try { | |
await collectAsyncIterable(pooledMap(10, iter, async (num) => { | |
await cb(num); | |
})); | |
} catch(err) { | |
console.error("caught", err); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment