File tree Expand file tree Collapse file tree 2 files changed +26
-12
lines changed
Expand file tree Collapse file tree 2 files changed +26
-12
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { promisify } from "util";
22import stream from "stream" ;
33import { ReadyContext } from "./interfaces/ReadyContext" ;
44import { onceTcpPortUsed } from "./util/onceTcpPortUsed" ;
5+ import { onceOutputLine } from "./util/onceOutputLine" ;
56
67const delay = promisify ( setTimeout ) ;
78
@@ -14,15 +15,3 @@ export function createReadyContext(output: stream.Readable): ReadyContext {
1415 onceDelay : milliseconds => delay ( milliseconds ) ,
1516 } ;
1617}
17-
18- function onceOutputLine ( output : stream . Readable , test : ( line : string ) => boolean ) : Promise < void > {
19- return new Promise < void > ( resolve => {
20- const handler = ( line : string ) => {
21- if ( test ( line ) ) {
22- output . off ( "data" , handler ) ;
23- resolve ( ) ;
24- }
25- } ;
26- output . on ( "data" , handler ) ;
27- } ) ;
28- }
Original file line number Diff line number Diff line change 1+ import stream from "stream" ;
2+
3+ export function onceOutputLine (
4+ output : stream . Readable ,
5+ test : ( line : string ) => boolean ,
6+ ) : Promise < void > {
7+ return new Promise < void > ( ( resolve , reject ) => {
8+ const handler = ( line : string ) => {
9+ let testResult = false ;
10+ try {
11+ testResult = test ( line ) ;
12+ } catch ( error ) {
13+ cleanup ( ) ;
14+ reject ( error ) ;
15+ return ;
16+ }
17+ if ( testResult ) {
18+ cleanup ( ) ;
19+ resolve ( ) ;
20+ }
21+ } ;
22+ output . on ( "data" , handler ) ;
23+ const cleanup = ( ) => output . off ( "data" , handler ) ;
24+ } ) ;
25+ }
You can’t perform that action at this time.
0 commit comments