1 | import { AsyncIterableX } from './asynciterablex';
|
2 | import { returnAsyncIterator } from '../util/returniterator';
|
3 | export class CatchAllAsyncIterable extends AsyncIterableX {
|
4 | constructor(source) {
|
5 | super();
|
6 | this._source = source;
|
7 | }
|
8 | async *[Symbol.asyncIterator]() {
|
9 | let error = null;
|
10 | let hasError = false;
|
11 | for (const source of this._source) {
|
12 | const it = source[Symbol.asyncIterator]();
|
13 | error = null;
|
14 | hasError = false;
|
15 | while (1) {
|
16 | let c = {};
|
17 | try {
|
18 | const { done, value } = await it.next();
|
19 | if (done) {
|
20 | await returnAsyncIterator(it);
|
21 | break;
|
22 | }
|
23 | c = value;
|
24 | }
|
25 | catch (e) {
|
26 | error = e;
|
27 | hasError = true;
|
28 | await returnAsyncIterator(it);
|
29 | break;
|
30 | }
|
31 | yield c;
|
32 | }
|
33 | if (!hasError) {
|
34 | break;
|
35 | }
|
36 | }
|
37 | if (hasError) {
|
38 | throw error;
|
39 | }
|
40 | }
|
41 | }
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | export function catchAll(source) {
|
48 | return new CatchAllAsyncIterable(source);
|
49 | }
|
50 | export function catchError(...args) {
|
51 | return new CatchAllAsyncIterable(args);
|
52 | }
|
53 |
|
54 |
|