import { AsyncIterableX } from '../asynciterablex' ; import { OperatorAsyncFunction } from '../../interfaces' ; import { wrapWithAbort } from './withabort' ; import { throwIfAborted } from '../../aborterror' ; export interface Timestamp < TSource > { time : number ; value : TSource ; } export class TimestampAsyncIterable < TSource > extends AsyncIterableX < Timestamp < TSource > > { private _source : AsyncIterable < TSource > ; constructor ( source ) { super ( ) ; this . _source = source ; } async * [ Symbol . asyncIterator ] ( signal ? ) { throwIfAborted ( signal ) ; for await ( const item of wrapWithAbort ( this . _source , signal ) ) { yield { time : Date . now ( ) , value : item } ; } } } template TSource returns { OperatorAsyncFunction < TSource , Timestamp < TSource > > } export function timestamp < TSource > ( ) { return function timestampOperatorFunction ( source ) : AsyncIterableX < Timestamp < TSource > > { return new TimestampAsyncIterable < TSource > ( source ) ; } ; }