GeezerVison is showing github.com — child_process: reduce abort handler code duplication · nodejs/node@b98cc51
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/child_process.js +9-8Lines changed: 9 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -368,6 +368,12 @@ function execFile(file /* , args, options, callback */) { |
368 | 368 | } |
369 | 369 | } |
370 | 370 |
|
| 371 | + function abortHandler() { |
| 372 | + if (!ex) |
| 373 | + ex = new AbortError(); |
| 374 | + process.nextTick(() => kill()); |
| 375 | + } |
| 376 | + |
371 | 377 | if (options.timeout > 0) { |
372 | 378 | timeoutId = setTimeout(function delayedKill() { |
373 | 379 | kill(); |
@@ -376,16 +382,11 @@ function execFile(file /* , args, options, callback */) { |
376 | 382 | } |
377 | 383 | if (options.signal) { |
378 | 384 | if (options.signal.aborted) { |
379 | | - if (!ex) |
380 | | - ex = new AbortError(); |
381 | | - process.nextTick(() => kill()); |
| 385 | + process.nextTick(abortHandler); |
382 | 386 | } else { |
383 | 387 | const childController = new AbortController(); |
384 | | - options.signal.addEventListener('abort', () => { |
385 | | - if (!ex) |
386 | | - ex = new AbortError(); |
387 | | - kill(); |
388 | | - }, { signal: childController.signal }); |
| 388 | + options.signal.addEventListener('abort', abortHandler, |
| 389 | + { signal: childController.signal }); |
389 | 390 | child.once('close', () => childController.abort()); |
390 | 391 | } |
391 | 392 | } |
|