Skip to content

Instantly share code, notes, and snippets.

@wperron
Created January 9, 2021 01:47
Show Gist options
  • Save wperron/1066ad43a77a3cd7aeb3bdecfa44d9d1 to your computer and use it in GitHub Desktop.
Save wperron/1066ad43a77a3cd7aeb3bdecfa44d9d1 to your computer and use it in GitHub Desktop.
Example of exception thrown in pooledMap not getting caught
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