ix
Version:
The Interactive Extensions for JavaScript
73 lines (71 loc) • 2.81 kB
JavaScript
import { __asyncGenerator, __await } from "tslib";
import { AsyncIterableX } from './asynciterablex.mjs';
import { returnAsyncIterator } from '../util/returniterator.mjs';
import { wrapWithAbort } from './operators/withabort.mjs';
import { throwIfAborted } from '../aborterror.mjs';
/** @ignore */
export class CatchAllAsyncIterable extends AsyncIterableX {
constructor(source) {
super();
this._source = source;
}
[Symbol.asyncIterator](signal) {
return __asyncGenerator(this, arguments, function* _a() {
throwIfAborted(signal);
let error = null;
let hasError = false;
for (const source of this._source) {
const it = wrapWithAbort(source, signal)[Symbol.asyncIterator]();
error = null;
hasError = false;
while (1) {
let c = {};
try {
const { done, value } = yield __await(it.next());
if (done) {
yield __await(returnAsyncIterator(it));
break;
}
c = value;
}
catch (e) {
error = e;
hasError = true;
yield __await(returnAsyncIterator(it));
break;
}
yield yield __await(c);
}
if (!hasError) {
break;
}
}
if (hasError) {
throw error;
}
});
}
}
/**
* Continues an async-iterable sequence that is terminated by an exception with the next async-iterable sequence.
*
* @template T The type of the elements in the source and handler sequences.
* @param {Iterable<AsyncIterable<T>>} source async-iterable sequences to catch exceptions for.
* @returns {AsyncIterableX<T>} An async-iterable sequence containing elements from consecutive source
* sequences until a source sequence terminates successfully.
*/
export function catchAll(source) {
return new CatchAllAsyncIterable(source);
}
/**
* Continues an async-iterable sequence that is terminated by an exception with the next async-iterable sequence.
*
* @template T The type of the elements in the source and handler sequences.
* @param {...AsyncIterable<T>[]} args async-iterable sequences to catch exceptions for.
* @returns {AsyncIterableX<T>} An async-iterable sequence containing elements from consecutive source
* sequences until a source sequence terminates successfully.
*/
export function catchError(...args) {
return new CatchAllAsyncIterable(args);
}
//# sourceMappingURL=catcherror.mjs.map