File tree 1 file changed +15
-12
lines changed
1 file changed +15
-12
lines changed Original file line number Diff line number Diff line change @@ -35,28 +35,31 @@ function normal(options: IPromptConfig, retries = 100): Promise<string> {
35
35
input : process . stdin ,
36
36
output : process . stdout ,
37
37
} )
38
+ let timeout : NodeJS . Timeout
39
+ if ( options . timeout ) {
40
+ timeout = setTimeout ( ( ) => ac . abort ( ) , options . timeout )
41
+ signal . addEventListener (
42
+ 'abort' ,
43
+ ( ) => {
44
+ rl . close ( )
45
+ clearTimeout ( timeout )
46
+ reject ( new Error ( 'Prompt timeout' ) )
47
+ } ,
48
+ { once : true } ,
49
+ )
50
+ }
38
51
39
52
rl . question ( options . prompt , { signal} , ( answer ) => {
40
53
rl . close ( )
41
54
const data = answer . trim ( )
42
55
if ( ! options . default && options . required && data === '' ) {
56
+ clearTimeout ( timeout )
43
57
resolve ( normal ( options , retries - 1 ) )
44
58
} else {
59
+ clearTimeout ( timeout )
45
60
resolve ( data || ( options . default as string ) )
46
61
}
47
62
} )
48
-
49
- if ( options . timeout ) {
50
- signal . addEventListener (
51
- 'abort' ,
52
- ( ) => {
53
- reject ( new Error ( 'Prompt timeout' ) )
54
- } ,
55
- { once : true } ,
56
- )
57
-
58
- setTimeout ( ( ) => ac . abort ( ) , options . timeout )
59
- }
60
63
} )
61
64
}
62
65
You can’t perform that action at this time.
0 commit comments