33const common = require ( '../common' ) ;
44const ArrayStream = require ( '../common/arraystream' ) ;
55const assert = require ( 'assert' ) ;
6+ const events = require ( 'events' ) ;
67const { stripVTControlCharacters } = require ( 'internal/util/inspect' ) ;
78const repl = require ( 'repl' ) ;
89
@@ -27,31 +28,21 @@ class REPLStream extends ArrayStream {
2728 if ( chunkLines . length > 1 ) {
2829 this . lines . push ( ...chunkLines . slice ( 1 ) ) ;
2930 }
30- this . emit ( 'line' ) ;
31+ this . emit ( 'line' , this . lines [ this . lines . length - 1 ] ) ;
3132 if ( callback ) callback ( ) ;
3233 return true ;
3334 }
3435
35- wait ( ) {
36+ async wait ( ) {
3637 if ( this . waitingForResponse ) {
3738 throw new Error ( 'Currently waiting for response to another command' ) ;
3839 }
3940 this . lines = [ '' ] ;
40- return new Promise ( ( resolve , reject ) => {
41- const onError = ( err ) => {
42- this . removeListener ( 'line' , onLine ) ;
43- reject ( err ) ;
44- } ;
45- const onLine = ( ) => {
46- if ( this . lines [ this . lines . length - 1 ] . includes ( PROMPT ) ) {
47- this . removeListener ( 'error' , onError ) ;
48- this . removeListener ( 'line' , onLine ) ;
49- resolve ( this . lines ) ;
50- }
51- } ;
52- this . once ( 'error' , onError ) ;
53- this . on ( 'line' , onLine ) ;
54- } ) ;
41+ for await ( const [ line ] of events . on ( this , 'line' ) ) {
42+ if ( line . includes ( PROMPT ) ) {
43+ return this . lines ;
44+ }
45+ }
5546 }
5647}
5748
0 commit comments