1
1
/// <reference path="../../types.d.ts" />
2
2
3
3
import { Deferred , deferred } from "./deps.ts" ;
4
+ import { readLines } from "./lib/readline.ts" ;
4
5
import { ProcessError } from "./process_error.ts" ;
5
6
import { ProcessOutput } from "./process_output.ts" ;
6
7
@@ -21,6 +22,7 @@ export class Process implements Promise<ProcessOutput> {
21
22
#maxRetries = 0 ;
22
23
#retries = 0 ;
23
24
#throwErrors = true ;
25
+ #isKilled = false ;
24
26
25
27
constructor ( cmd : string , { errorContext } : ProcessOptions = { } ) {
26
28
this . #cmd = cmd ;
@@ -66,6 +68,7 @@ export class Process implements Promise<ProcessOutput> {
66
68
}
67
69
68
70
kill ( signo : Deno . Signal ) : void {
71
+ this . #isKilled = true ;
69
72
this . #process. kill ( signo ) ;
70
73
}
71
74
@@ -117,9 +120,19 @@ export class Process implements Promise<ProcessOutput> {
117
120
const [ status ] = await Promise . all ( [
118
121
this . #process. status ( ) ,
119
122
this . #process. stdout &&
120
- read ( this . #process. stdout , [ stdout , combined ] , Deno . stdout ) ,
123
+ read (
124
+ this . #process. stdout ,
125
+ [ stdout , combined ] ,
126
+ Deno . stdout ,
127
+ ( ) => this . #isKilled,
128
+ ) ,
121
129
this . #process. stderr &&
122
- read ( this . #process. stderr , [ stderr , combined ] , Deno . stderr ) ,
130
+ read (
131
+ this . #process. stderr ,
132
+ [ stderr , combined ] ,
133
+ Deno . stderr ,
134
+ ( ) => this . #isKilled,
135
+ ) ,
123
136
] ) ;
124
137
125
138
let output = new ProcessOutput ( {
@@ -169,8 +182,9 @@ async function read(
169
182
reader : Deno . Reader ,
170
183
results : Array < Array < string > > ,
171
184
outputStream : Deno . Writer ,
185
+ isCanceld : ( ) => boolean ,
172
186
) : Promise < Error | void > {
173
- for await ( const line of io . readLines ( reader ) ) {
187
+ for await ( const line of readLines ( reader , isCanceld ) ) {
174
188
for ( const result of results ) {
175
189
result . push ( line + "\n" ) ;
176
190
}
0 commit comments