import { _ } from 'streamline-runtime' ; import { Reader } from '../reader' ; import { Writer } from '../writer' ; import { nextTick } from '../util' ; export interface Options { sync ? : boolean ; } export class ArrayWriter < T > extends Writer < T > { values : T [ ] ; constructor ( options ) { super ( ( _ , value ) => { if ( ! options . sync ) nextTick ( _ ) ; if ( value !== undefined ) this . values . push ( value ) ; return this ; } ) ; this . values = [ ] ; } toArray ( ) { return this . values ; } get result ( ) : T [ ] { return this . values ; } } export function reader < T > ( array , options ? ) { var opts = options || { } ; const values = array . slice ( 0 ) ; return new Reader ( function ( _ ) { if ( ! opts . sync ) nextTick ( _ ) ; return values . shift ( ) ; } ) ; } export function writer < T > ( options ? ) { var opts = options || { } ; return new ArrayWriter ( opts ) ; } ;