import { Remote } from "intern/lib/executors/Node" ; export class RemoteChannel < T > { readonly remote : Remote ; readonly identifier : string ; private index : number = 0 ; constructor ( remote , identifier ) { this . remote = remote ; this . identifier = identifier ; } async read ( length ? ) { const records = ( await this . newRecords ) . slice ( 0 , length ) ; this . index += records . length ; return records ; } async drain ( ) { await this . read ( ) ; } private get newRecords ( ) { return this . remote . execute ( ( identifier , index ) => { const records = ( window as any ) [ identifier ] ; if ( records != null && typeof records . slice == "function" ) { return records . slice ( index ) ; } else { return [ ] ; } } , [ this . identifier , this . index ] ) ; } }