@reactivex/ix-esnext-esm
Version:
The Interactive Extensions for JavaScript
55 lines (53 loc) • 1.7 kB
JavaScript
import { AsyncIterableX } from './asynciterablex';
import { returnAsyncIterator } from '../util/returniterator';
export class CatchAllAsyncIterable extends AsyncIterableX {
constructor(source) {
super();
this._source = source;
}
async *[Symbol.asyncIterator]() {
let error = null;
let hasError = false;
for (const source of this._source) {
const it = source[Symbol.asyncIterator]();
error = null;
hasError = false;
while (1) {
let c = {};
try {
const { done, value } = await it.next();
if (done) {
await returnAsyncIterator(it);
break;
}
c = value;
}
catch (e) {
error = e;
hasError = true;
await returnAsyncIterator(it);
break;
}
yield c;
}
if (!hasError) {
break;
}
}
if (hasError) {
throw error;
}
}
}
/**
* Creates a sequence by concatenating source sequences until a source sequence completes successfully.
* @param {AsyncIterable<AsyncIterable<T>>} source Source sequences.
* @return {AsyncIterable<T>} Sequence that continues to concatenate source sequences while errors occur.
*/
export function catchAll(source) {
return new CatchAllAsyncIterable(source);
}
export function catchError(...args) {
return new CatchAllAsyncIterable(args);
}
//# sourceMappingURL=catcherror.mjs.map