@@ -154,39 +154,36 @@ export class ExecProcess implements Result {
154
154
await this . _processClosed ;
155
155
}
156
156
157
- public then < TResult1 = Output , TResult2 = never > (
157
+ public async then < TResult1 = Output , TResult2 = never > (
158
158
onfulfilled ?: ( ( value : Output ) => TResult1 | PromiseLike < TResult1 > ) | null ,
159
159
_onrejected ?: ( ( reason : unknown ) => TResult2 | PromiseLike < TResult2 > ) | null
160
- ) : PromiseLike < TResult1 | TResult2 > {
161
- return new Promise < TResult1 | TResult2 > ( async ( resolve , reject ) => {
162
- if ( this . _options ?. stdin ) {
163
- await this . _options . stdin ;
164
- }
160
+ ) : Promise < TResult1 | TResult2 > {
161
+ if ( this . _options ?. stdin ) {
162
+ await this . _options . stdin ;
163
+ }
165
164
166
- const proc = this . _process ;
165
+ const proc = this . _process ;
167
166
168
- if ( ! proc ) {
169
- reject ( new Error ( 'No process was started' ) ) ;
170
- return ;
171
- }
167
+ if ( ! proc ) {
168
+ throw new Error ( 'No process was started' ) ;
169
+ }
172
170
173
- const [ stderr , stdout ] = await Promise . all ( [
174
- proc . stderr && readStreamAsString ( proc . stderr ) ,
175
- proc . stdout && readStreamAsString ( proc . stdout ) ,
176
- this . _processClosed
177
- ] ) ;
178
-
179
- const result : Output = {
180
- stderr : stderr ?? '' ,
181
- stdout : stdout ?? ''
182
- } ;
183
-
184
- if ( onfulfilled ) {
185
- resolve ( onfulfilled ( result ) ) ;
186
- } else {
187
- resolve ( result as TResult1 ) ;
188
- }
189
- } ) ;
171
+ const [ stderr , stdout ] = await Promise . all ( [
172
+ proc . stderr && readStreamAsString ( proc . stderr ) ,
173
+ proc . stdout && readStreamAsString ( proc . stdout ) ,
174
+ this . _processClosed
175
+ ] ) ;
176
+
177
+ const result : Output = {
178
+ stderr : stderr ?? '' ,
179
+ stdout : stdout ?? ''
180
+ } ;
181
+
182
+ if ( onfulfilled ) {
183
+ return onfulfilled ( result ) ;
184
+ } else {
185
+ return result as TResult1 ;
186
+ }
190
187
}
191
188
192
189
public spawn ( ) : void {
@@ -214,14 +211,7 @@ export class ExecProcess implements Result {
214
211
const { command : normalisedCommand , args : normalisedArgs } =
215
212
normaliseCommandAndArgs ( this . _command , this . _args ) ;
216
213
217
- let handle ;
218
-
219
- try {
220
- handle = spawn ( normalisedCommand , normalisedArgs , nodeOptions ) ;
221
- } catch ( err ) {
222
- // TODO (jg): handle errors
223
- throw err ;
224
- }
214
+ const handle = spawn ( normalisedCommand , normalisedArgs , nodeOptions ) ;
225
215
226
216
this . _process = handle ;
227
217
handle . once ( 'error' , this . _onError ) ;
0 commit comments