/**
 * Promise-based object stream with seamless support for back-pressure and error
 * handling, written in Typescript.
 *
 * Copyright (C) 2017 Martin Poelstra
 * License: MIT
 */ import { defer } from "../lib/util" ; import { ReadableStream } from "../lib" ; import { expect } from "chai" ; export * from "../lib/util" ; param promises export function settle ( promises ) { const result = defer ( ) ; let count = promises . length ; const check = ( ) : void => { count -- ; if ( count === 0 ) { result . resolve ( ) ; } } ; for ( const promise of promises ) { promise . then ( check , check ) ; } return result . promise ; } export function readInto < T > ( stream , into ) { return new Promise < void > ( ( resolve , reject ) => { stream . forEach ( function ( this , value ) : void { expect ( this ) . to . equal ( undefined ) ; into . push ( value ) ; } , function ( this , err ? ) : void { expect ( this ) . to . equal ( undefined ) ; if ( err ) { reject ( err ) ; } else { resolve ( undefined ) ; } } ) ; } ) ; } export function noop ( ) { } export function identity < T > ( arg ) { return arg ; }