blob: 2591fb56a30540512a1d9656d84cfc90a450b24b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
export const any = {
async any<T>(iterable: Iterable<T | PromiseLike<T>>): Promise<T> {
return Promise.all(
[...iterable].map((promise) => {
return new Promise((resolve, reject) =>
Promise.resolve(promise).then(reject, resolve)
)
})
).then(
(errors) => Promise.reject(errors),
(value) => Promise.resolve<T>(value)
)
},
}.any
export const initPromise = (target: any, exclude: Set<string>) => {
if (exclude.has('Promise') || exclude.has('any')) return
const Class = target.Promise || globalThis.Promise
if (!Class.any)
Object.defineProperty(Class, 'any', {
value: any,
writable: true,
enumerable: false,
configurable: true,
})
}
|