UNPKG

@reactivex/ix-es5-esm

Version:

The Interactive Extensions for JavaScript

47 lines (45 loc) 1.92 kB
import { __extends } from "tslib"; import { AsyncIterableX } from '../asynciterablex.js'; /** @ignore */ var WithAbortAsyncIterable = /** @class */ (function (_super) { __extends(WithAbortAsyncIterable, _super); function WithAbortAsyncIterable(source, signal) { var _this = _super.call(this) || this; _this._source = source; _this._signal = signal; return _this; } WithAbortAsyncIterable.prototype.withAbort = function (signal) { return new WithAbortAsyncIterable(this._source, signal); }; WithAbortAsyncIterable.prototype[Symbol.asyncIterator] = function () { // @ts-ignore return this._source[Symbol.asyncIterator](this._signal); }; return WithAbortAsyncIterable; }(AsyncIterableX)); export { WithAbortAsyncIterable }; /** * Wraps the existing async-iterable sequence with an abort signal for cancellation. * * @template TSource The type of the elements in the source sequence. * @param {AbortSignal} signal The abort signal used for cancellation. * @returns {MonoTypeOperatorAsyncFunction<TSource>} An async-iterable that can be cancelled by the abort signal. */ export function withAbort(signal) { return function withAbortOperatorFunction(source) { return new WithAbortAsyncIterable(source, signal); }; } /** * Wraps an existing async-iterable with a new async-iterable which support cancellation. * * @template TSource The type of the elements in the source sequence. * @param {AsyncIterable<TSource>} source The source sequence to wrap with the abort signal. * @param {AbortSignal} [signal] The abort signal used for cancellation. * @returns {AsyncIterable<TSource>} The source sequence wrapped with an abort signal for cancellation. */ export function wrapWithAbort(source, signal) { return signal ? new WithAbortAsyncIterable(source, signal) : source; } //# sourceMappingURL=withabort.js.map