UNPKG

@reactivex/ix-es5-esm

Version:

The Interactive Extensions for JavaScript

41 lines (39 loc) 1.9 kB
import { __awaiter, __extends, __generator } from "tslib"; import { RefCountList } from '../../iterable/operators/_refcountlist.js'; import { create } from '../create.js'; import { MemoizeAsyncBuffer } from './memoize.js'; import { throwIfAborted } from '../../aborterror.js'; var PublishedAsyncBuffer = /** @class */ (function (_super) { __extends(PublishedAsyncBuffer, _super); function PublishedAsyncBuffer(source) { return _super.call(this, source, new RefCountList(0)) || this; } PublishedAsyncBuffer.prototype[Symbol.asyncIterator] = function (signal) { throwIfAborted(signal); this._buffer.readerCount++; return this._getIterable(this._buffer.count)[Symbol.asyncIterator](); }; return PublishedAsyncBuffer; }(MemoizeAsyncBuffer)); /** * Buffer enabling each iterator to retrieve elements from the shared source sequence, starting from the * index at the point of obtaining the iterator. * * @template TSource Source sequence element type. * @template TResult Result sequence element type. * @param {(value: AsyncIterable<TSource>) => AsyncIterable<TResult>} [selector] Selector function with published * access to the source sequence for each iterator. * @returns {(OperatorAsyncFunction<TSource, TSource | TResult>)} Sequence resulting from applying the selector function to the * published view over the source sequence. */ export function publish(selector) { return function publishOperatorFunction(source) { var _this = this; return selector ? create(function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, selector(publish()(source))[Symbol.asyncIterator]()]; }); }); }) : new PublishedAsyncBuffer(source[Symbol.asyncIterator]()); }; } //# sourceMappingURL=publish.js.map