feat(lib/utils): export promises
This commit is contained in:
parent
96ff348fd8
commit
8a8bbf7c8a
2 changed files with 24 additions and 0 deletions
|
|
@ -21,6 +21,9 @@
|
|||
"./objects": {
|
||||
"default": "./src/objects.ts"
|
||||
},
|
||||
"./promises": {
|
||||
"default": "./src/promises.ts"
|
||||
},
|
||||
"./proxy": {
|
||||
"default": "./src/proxy.ts"
|
||||
},
|
||||
|
|
|
|||
21
lib/utils/src/promises.ts
Normal file
21
lib/utils/src/promises.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
export function allSettled(promises: Promise<any>[]): Promise<PromiseSettledResult<any>[]> {
|
||||
const mapped = promises.map(p =>
|
||||
p
|
||||
?.then(
|
||||
value =>
|
||||
({
|
||||
status: 'fulfilled',
|
||||
value,
|
||||
}) as const,
|
||||
)
|
||||
.catch(
|
||||
reason =>
|
||||
({
|
||||
status: 'rejected',
|
||||
reason,
|
||||
}) as const,
|
||||
),
|
||||
)
|
||||
|
||||
return Promise.all(mapped)
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue