ix
Version:
The Interactive Extensions for JavaScript
40 lines (38 loc) • 1.76 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.publish = void 0;
const tslib_1 = require("tslib");
const _refcountlist_js_1 = require("../../iterable/operators/_refcountlist.js");
const create_js_1 = require("../create.js");
const memoize_js_1 = require("./memoize.js");
const aborterror_js_1 = require("../../aborterror.js");
class PublishedAsyncBuffer extends memoize_js_1.MemoizeAsyncBuffer {
constructor(source) {
super(source, new _refcountlist_js_1.RefCountList(0));
}
[Symbol.asyncIterator](signal) {
(0, aborterror_js_1.throwIfAborted)(signal);
this._buffer.readerCount++;
return this._getIterable(this._buffer.count)[Symbol.asyncIterator]();
}
}
/**
* 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.
*/
function publish(selector) {
return function publishOperatorFunction(source) {
return selector
? (0, create_js_1.create)(() => tslib_1.__awaiter(this, void 0, void 0, function* () { return selector(publish()(source))[Symbol.asyncIterator](); }))
: new PublishedAsyncBuffer(source[Symbol.asyncIterator]());
};
}
exports.publish = publish;
//# sourceMappingURL=publish.js.map