import { rpc } from '@deepkit/rpc' ; import { Observable , Subject } from 'rxjs' ; import { t } from '@deepkit/type' ; @ rpc . controller ( 'test-rpc' ) export class RpcController { @ rpc . action ( ) @ t . generic ( Date ) timesSubject ( ) { const subject = new Subject < Date > ( ) ; const interval = setInterval ( ( ) => { subject . next ( new Date ) ; } , 1000 ) ; setTimeout ( ( ) => { subject . complete ( ) ; } , 10000 ) ; subject . subscribe ( ) . add ( ( ) => { clearTimeout ( interval ) ; } ) ; return subject ; } @ rpc . action ( ) @ t . generic ( Date ) timesObservable ( ) { return new Observable ( ( observer ) => { const interval = setInterval ( ( ) => { observer . next ( new Date ) ; } , 1000 ) ; setTimeout ( ( ) => { observer . complete ( ) ; clearTimeout ( interval ) ; } , 10000 ) ; return { unsubscribe ( ) { clearTimeout ( interval ) ; } } ; } ) ; } }