Skip to content
Myr

Separate `cleanup` option handling into its own function (#307)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by ehmicky · committed by Sindre Sorhus · parent b979534 · Browse files · 1 file+14 added−10 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+14 added−10 removed

  • other:+14 added−10 removed

1 file+14 added−10 removed

modified:index.js+14 added-10 removed
332 unmodified lines
333 }, timeout);334 }335};336337// #115338const setExitHandler = (spawned, {cleanup, detached}, context) => {339 if (!cleanup || detached) {340 return;341 }342343 context.removeExitHandler = onExit(() => {344 spawned.kill();345 });346};347348const execa = (file, args, options) => {349 const parsed = handleArgs(file, args, options);350 const command = joinCommand(file, args);351
14 unmodified lines
366367 const kill = spawned.kill.bind(spawned);368 spawned.kill = spawnedKill.bind(null, kill);369359 // #115360 let removeExitHandler;361 if (parsed.options.cleanup && !parsed.options.detached) {362 removeExitHandler = onExit(() => {363 spawned.kill();364 });365 }366370 const context = {timedOut: false};371 let isCanceled = false;372373 const cleanup = () => {
1 unmodified line
375 clearTimeout(context.timeoutId);376 context.timeoutId = undefined;377 }378376 if (removeExitHandler) {377 removeExitHandler();379 if (context.removeExitHandler) {380 context.removeExitHandler();381 }382 };383384 setExitHandler(spawned, parsed.options, context);385 setupTimeout(spawned, parsed.options, context);386387 // TODO: Use native "finally" syntax when targeting Node.js 10388 const processDone = pFinally(handleSpawned(spawned, context), cleanup);
168 unmodified lines