UNPKG

@reactivex/ix-esnext-esm

Version:

The Interactive Extensions for JavaScript

1 lines 4.14 kB
{"version":3,"sources":["asynciterable/operators/publish.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,MAAM,oBAAwB,SAAQ,kBAAqB;IAIzD,YAAY,MAAwB;QAClC,KAAK,CAAC,MAAM,EAAE,IAAI,YAAY,CAAI,CAAC,CAAC,CAAC,CAAC;IACxC,CAAC;IAED,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,MAAoB;QACzC,cAAc,CAAC,MAAM,CAAC,CAAC;QACvB,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;QAC3B,OAAO,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC;IACvE,CAAC;CACF;AA2BD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,OAAO,CACrB,QAAoE;IAEpE,OAAO,SAAS,uBAAuB,CACrC,MAA8B;QAE9B,OAAO,QAAQ;YACb,CAAC,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,QAAQ,CAAC,OAAO,EAAW,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC;YAClF,CAAC,CAAC,IAAI,oBAAoB,CAAU,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;IACxE,CAAC,CAAC;AACJ,CAAC","file":"publish.js","sourcesContent":["import { AsyncIterableX } from '../asynciterablex';\nimport { RefCountList } from '../../iterable/operators/_refcountlist';\nimport { create } from '../create';\nimport { OperatorAsyncFunction } from '../../interfaces';\nimport { MemoizeAsyncBuffer } from './memoize';\nimport { throwIfAborted } from '../../aborterror';\n\nclass PublishedAsyncBuffer<T> extends MemoizeAsyncBuffer<T> {\n // @ts-ignore\n protected _buffer: RefCountList<T>;\n\n constructor(source: AsyncIterator<T>) {\n super(source, new RefCountList<T>(0));\n }\n\n [Symbol.asyncIterator](signal?: AbortSignal) {\n throwIfAborted(signal);\n this._buffer.readerCount++;\n return this._getIterable(this._buffer.count)[Symbol.asyncIterator]();\n }\n}\n\n/**\n * Creates a buffer with a view over the source sequence, causing each iterator to obtain access to the\n * remainder of the sequence from the current index in the buffer.\n *\n * @export\n * @template TSource Source sequence element type.\n * @returns {OperatorAsyncFunction<TSource, TSource>} Buffer enabling each iterator to retrieve elements from\n * the shared source sequence, starting from the index at the point of obtaining the enumerator.\n */\nexport function publish<TSource>(): OperatorAsyncFunction<TSource, TSource>;\n/**\n * Buffer enabling each iterator to retrieve elements from the shared source sequence, starting from the\n * index at the point of obtaining the iterator.\n *\n * @export\n * @template TSource Source sequence element type.\n * @template TResult Result sequence element type.\n * @param {(value: AsyncIterable<TSource>) => AsyncIterable<TResult>} [selector] Selector function with published\n * access to the source sequence for each iterator.\n * @returns {OperatorAsyncFunction<TSource, TResult>} Sequence resulting from applying the selector function to the\n * published view over the source sequence.\n */\nexport function publish<TSource, TResult>(\n selector?: (value: AsyncIterable<TSource>) => AsyncIterable<TResult>\n): OperatorAsyncFunction<TSource, TResult>;\n/**\n * Buffer enabling each iterator to retrieve elements from the shared source sequence, starting from the\n * index at the point of obtaining the iterator.\n *\n * @export\n * @template TSource Source sequence element type.\n * @template TResult Result sequence element type.\n * @param {(value: AsyncIterable<TSource>) => AsyncIterable<TResult>} [selector] Selector function with published\n * access to the source sequence for each iterator.\n * @returns {(OperatorAsyncFunction<TSource, TSource | TResult>)} Sequence resulting from applying the selector function to the\n * published view over the source sequence.\n */\nexport function publish<TSource, TResult>(\n selector?: (value: AsyncIterable<TSource>) => AsyncIterable<TResult>\n): OperatorAsyncFunction<TSource, TSource | TResult> {\n return function publishOperatorFunction(\n source: AsyncIterable<TSource>\n ): AsyncIterableX<TSource | TResult> {\n return selector\n ? create(async () => selector(publish<TSource>()(source))[Symbol.asyncIterator]())\n : new PublishedAsyncBuffer<TSource>(source[Symbol.asyncIterator]());\n };\n}\n"]}