import { Observable , ConnectableObservable } from 'rxjs' ; import { publishLast } from 'rxjs/operators' ; const cold$ = new Observable < number > ( observer => { for ( let item of [ 42 , 56 ] ) { console . log ( `Observable next: ${ item }` ) ; observer . next ( item ) ; } observer . complete ( ) ; } ) ; const hot$ = cold$ . pipe ( publishLast ( ) ) as ConnectableObservable < number > ; const subcription1 = hot$ . subscribe ( { next : item => console . log ( `Subscription 1: ${ item }` ) } ) ; const subcription2 = hot$ . subscribe ( { next : item => console . log ( `Subscription 2: ${ item }` ) } ) ; hot$ . connect ( ) ; const subcription3 = hot$ . subscribe ( { next : item => console . log ( `Subscription 3: ${ item }` ) } ) ;