init; collecting some of my commonly used utils

This commit is contained in:
2024-04-01 17:31:33 -05:00
commit a09a7d7337
13 changed files with 322 additions and 0 deletions

14
pkg/async.ts Normal file
View File

@@ -0,0 +1,14 @@
export async function promiseAllSafe<T>(tasks: Promise<T>[]) {
return await Promise.allSettled(tasks)
.then(res => {
const fulfilled: NonNullable<T>[] = [];
res.forEach(r => {
if (r.status == 'fulfilled' && r.value) {
fulfilled.push(r.value);
}
});
return fulfilled;
}) satisfies Awaited<NonNullable<T>[]>;
}