File tree Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -7,16 +7,22 @@ export async function match(
77 /** Measured in ms */
88 timeout ?: number ;
99 } = { } ,
10- ) : Promise < string > {
10+ ) : Promise < RegExpMatchArray > {
1111 // Prepare error outside of promise so that stacktrace points to caller of `matchLine`
12- const timeout = new Error ( `Timed out - Could not find pattern: ${ pattern } ` ) ;
13- return new Promise < string > ( async ( resolve , reject ) => {
14- setTimeout ( ( ) => reject ( timeout ) , options . timeout ?? 10_000 ) ;
12+ const timeoutError = new Error (
13+ `Timed out - Could not find pattern: ${ pattern } ` ,
14+ ) ;
15+ return new Promise ( async ( resolve , reject ) => {
16+ const timeout = setTimeout (
17+ ( ) => reject ( timeoutError ) ,
18+ options . timeout ?? 10_000 ,
19+ ) ;
1520 stream . on ( "data" , ( data ) => {
1621 const line : string = data . toString ( ) ;
1722 const matches = line . match ( pattern ) ;
1823 if ( matches ) {
19- resolve ( matches [ 0 ] ) ;
24+ resolve ( matches ) ;
25+ clearTimeout ( timeout ) ;
2026 }
2127 } ) ;
2228 } ) ;
You can’t perform that action at this time.
0 commit comments