UNPKG

@reactivex/ix-es2015-cjs

Version:

The Interactive Extensions for JavaScript

65 lines (63 loc) 2.98 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.tap = exports.TapAsyncIterable = void 0; const tslib_1 = require("tslib"); const asynciterablex_js_1 = require("../asynciterablex.js"); const toobserver_js_1 = require("../../util/toobserver.js"); const aborterror_js_1 = require("../../aborterror.js"); const returniterator_js_1 = require("../../util/returniterator.js"); /** @ignore */ class TapAsyncIterable extends asynciterablex_js_1.AsyncIterableX { constructor(source, observer) { super(); this._source = source; this._observer = observer; } [Symbol.asyncIterator](signal) { return tslib_1.__asyncGenerator(this, arguments, function* _a() { (0, aborterror_js_1.throwIfAborted)(signal); const obs = this._observer; const it = this._source[Symbol.asyncIterator](signal); try { for (let res; !(res = yield tslib_1.__await(it.next())).done;) { if (obs.next) { yield tslib_1.__await(obs.next(res.value)); } yield yield tslib_1.__await(res.value); } if (obs.complete) { yield tslib_1.__await(obs.complete()); } } catch (e) { if (!(e instanceof aborterror_js_1.AbortError) && obs.error) { yield tslib_1.__await(obs.error(e)); } throw e; } finally { yield tslib_1.__await((0, returniterator_js_1.returnAsyncIterator)(it)); } }); } } exports.TapAsyncIterable = TapAsyncIterable; /** * Invokes an action for each element in the async-iterable sequence, and propagates all observer * messages through the result sequence. This method can be used for debugging, logging, etc. by * intercepting the message stream to run arbitrary actions for messages on the pipeline. * * @template TSource The type of the elements in the source sequence. * @param {(PartialAsyncObserver<TSource> | ((value: TSource) => any) | null)} [observerOrNext] Observer whose methods to invoke as * part of the source sequence's observation or a function to invoke for each element in the async-iterable sequence. * @param {(((err: any) => any) | null)} [error] Function to invoke upon exceptional termination of the async-iterable sequence. * @param {((() => any) | null)} [complete] Function to invoke upon graceful termination of the async-iterable sequence. * @returns {MonoTypeOperatorAsyncFunction<TSource>} The source sequence with the side-effecting behavior applied. */ function tap(observerOrNext, error, complete) { return function tapOperatorFunction(source) { return new TapAsyncIterable(source, (0, toobserver_js_1.toObserver)(observerOrNext, error, complete)); }; } exports.tap = tap; //# sourceMappingURL=tap.js.map