main
Last change
on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
603 bytes
|
Line | |
---|
1 | import { map } from 'ramda';
|
---|
2 |
|
---|
3 | import resolveP from '../../resolveP';
|
---|
4 |
|
---|
5 | export class AggregatedError extends Error {
|
---|
6 | constructor(errors = [], message = '') {
|
---|
7 | super(message);
|
---|
8 |
|
---|
9 | this.errors = errors;
|
---|
10 | }
|
---|
11 | }
|
---|
12 |
|
---|
13 | const anyPonyfill = (iterable) => {
|
---|
14 | const exceptions = [];
|
---|
15 |
|
---|
16 | return new Promise((resolve, reject) => {
|
---|
17 | const onReject = (e) => {
|
---|
18 | exceptions.push(e);
|
---|
19 |
|
---|
20 | if (exceptions.length === iterable.length) {
|
---|
21 | reject(new AggregatedError(exceptions));
|
---|
22 | }
|
---|
23 | };
|
---|
24 |
|
---|
25 | map((p) => resolveP(p).then(resolve).catch(onReject), [...iterable]);
|
---|
26 | });
|
---|
27 | };
|
---|
28 |
|
---|
29 | export default anyPonyfill;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.