Skip to content

Commit b98cc51

Browse files
Trottdanielleadams
authored andcommitted
child_process: reduce abort handler code duplication
Move duplicate abort handler logic into a separate function. PR-URL: #36644 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Daijiro Wachi <[email protected]>
1 parent 78d4d91 commit b98cc51

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

‎lib/child_process.js‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,12 @@ function execFile(file /* , args, options, callback */){
368368
}
369369
}
370370

371+
functionabortHandler(){
372+
if(!ex)
373+
ex=newAbortError();
374+
process.nextTick(()=>kill());
375+
}
376+
371377
if(options.timeout>0){
372378
timeoutId=setTimeout(functiondelayedKill(){
373379
kill();
@@ -376,16 +382,11 @@ function execFile(file /* , args, options, callback */){
376382
}
377383
if(options.signal){
378384
if(options.signal.aborted){
379-
if(!ex)
380-
ex=newAbortError();
381-
process.nextTick(()=>kill());
385+
process.nextTick(abortHandler);
382386
}else{
383387
constchildController=newAbortController();
384-
options.signal.addEventListener('abort',()=>{
385-
if(!ex)
386-
ex=newAbortError();
387-
kill();
388-
},{signal: childController.signal});
388+
options.signal.addEventListener('abort',abortHandler,
389+
{signal: childController.signal});
389390
child.once('close',()=>childController.abort());
390391
}
391392
}

0 commit comments

Comments
(0)