import { AsyncIterableX } from './asynciterablex.js'; import { throwIfAborted } from '../aborterror.js'; class ThrowAsyncIterable extends AsyncIterableX { private _error: any; constructor(error: any) { super(); this._error = error; } async *[Symbol.asyncIterator](signal?: AbortSignal): AsyncIterator { throwIfAborted(signal); throw this._error; } } /** * Creates an async-iterable that throws the specified error upon iterating. * * @param {*} error The error to throw upon iterating the async-iterable. * @returns {AsyncIterableX} An async-iterable that throws when iterated. */ export function throwError(error: any): AsyncIterableX { return new ThrowAsyncIterable(error); }