init; collecting some of my commonly used utils
This commit is contained in:
14
pkg/async.ts
Normal file
14
pkg/async.ts
Normal 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>[]>;
|
||||
}
|
||||
Reference in New Issue
Block a user