import { StringStream } from "scramjet" ; import { InertApp } from "@scramjet/types" ; type { InertApp } param { Readable } _stream module . exports = async function ( _stream ) { this . logger . log ( 0 ) ; return StringStream . from ( process . stdin ) . lines ( "\n" ) . parse ( ( str ) => [ + ( str . match ( /^\w+/ ) || [ ] ) . pop ( ) , str ] ) . each ( ( item ) => this . logger . debug ( "item" , item ) ) . filter ( ( [ item ] ) => ! isNaN ( item ) ) . do ( async ( [ num , line ] ) => { const stream = num % 2 ? "stdout" : "stderr" ; const wrote = process [ stream ] . write ( line + "\n" ) ; this . logger . info ( "wrote" , num , stream , wrote ) ; if ( ! wrote ) await new Promise ( res => process [ stream ] . once ( "drain" , res ) ) ; } ) . run ( ) . then ( ( ) => { this . logger . log ( "Almost done" ) ; return new Promise ( res => setTimeout ( res , 100 ) ) ; } ) ; } as InertApp ;