import { AsyncIterableX } from '../asynciterablex' ; import { RefCountList } from '../../iterable/operators/_refcountlist' ; import { create } from '../create' ; import { OperatorAsyncFunction } from '../../interfaces' ; import { MemoizeAsyncBuffer } from './memoize' ; import { throwIfAborted } from '../../aborterror' ; class PublishedAsyncBuffer < T > extends MemoizeAsyncBuffer < T > { protected declare _buffer : RefCountList < T > ; constructor ( source ) { super ( source , new RefCountList < T > ( 0 ) ) ; } [ Symbol . asyncIterator ] ( signal ? ) { throwIfAborted ( signal ) ; this . _buffer . readerCount ++ ; return this . _getIterable ( this . _buffer . count ) [ Symbol . asyncIterator ] ( ) ; } } template TSource returns { OperatorAsyncFunction < TSource , TSource > } export function publish < TSource > ( ) ; template TSource template TResult param { ( value : AsyncIterable < TSource > ) => AsyncIterable < TResult > } selector returns { OperatorAsyncFunction < TSource , TResult > } export function publish < TSource , TResult > ( selector ? ) ; template TSource template TResult param { ( value : AsyncIterable < TSource > ) => AsyncIterable < TResult > } selector returns { ( OperatorAsyncFunction < TSource , TSource | TResult > ) } export function publish < TSource , TResult > ( selector ? ) { return function publishOperatorFunction ( source ) : AsyncIterableX < TSource | TResult > { return selector ? create ( async ( ) => selector ( publish < TSource > ( ) ( source ) ) [ Symbol . asyncIterator ] ( ) ) : new PublishedAsyncBuffer < TSource > ( source [ Symbol . asyncIterator ] ( ) ) ; } ; }