UNPKG

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