UNPKG

713 BJavaScriptView Raw
1import { AsyncIterableX } from './asynciterablex';
2import { throwIfAborted } from '../aborterror';
3class ThrowAsyncIterable extends AsyncIterableX {
4 constructor(error) {
5 super();
6 this._error = error;
7 }
8 async *[Symbol.asyncIterator](signal) {
9 throwIfAborted(signal);
10 throw this._error;
11 }
12}
13/**
14 * Creates an async-iterable that throws the specified error upon iterating.
15 *
16 * @export
17 * @param {*} error The error to throw upon iterating the async-iterable.
18 * @returns {AsyncIterableX<never>} An async-iterable that throws when iterated.
19 */
20export function throwError(error) {
21 return new ThrowAsyncIterable(error);
22}
23
24//# sourceMappingURL=throwerrror.mjs.map