import { AppConfig , AppContext } from "@scramjet/types" ; import { DataStream } from "scramjet" ; const rht = require ( "./real-hrtime.node" ) ; export default [ param { AppContext } this param _stream param { number } timesOfExecution param { number } waitToStart returns { DataStream } function ( this , _stream , timesOfExecution = 12000 , waitToStart = 20000 ) { this . logger . log ( `Testing ${ timesOfExecution } samples after ${ waitToStart } ms` ) ; return Object . assign ( DataStream . from ( async function * ( ) { await new Promise ( res => setTimeout ( res , waitToStart ) ) ; let x = 0 ; while ( ++ x <= timesOfExecution ) { await new Promise ( res => setTimeout ( res , 10 ) ) ; yield { i : x } ; } console . log ( "Done" , x ) ; } ) . map ( ( ) => rht . stringified ( ) + "\n" ) . on ( "error" , ( e ) => { this . logger . log ( "ERR" , e . message ) ; } ) , { topic : "delay-test" , contentType : "application/x-ndjson" } ) ; } ] ;