Skip to content
Myr

Separate `cleanup` into its own function (#308)

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 a9fa13f · Browse files · 1 file+13 added−12 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+13 added−12 removed

  • other:+13 added−12 removed

1 file+13 added−12 removed

modified:index.js+13 added-12 removed
343 unmodified lines
344 spawned.kill();345 });346};347348const cleanup = ({timeoutId, removeExitHandler}) => {349 if (timeoutId !== undefined) {350 clearTimeout(timeoutId);351 }352353 if (removeExitHandler !== undefined) {354 removeExitHandler();355 }356};357358const execa = (file, args, options) => {359 const parsed = handleArgs(file, args, options);360 const command = joinCommand(file, args);361
17 unmodified lines
379380 const context = {timedOut: false};381 let isCanceled = false;382373 const cleanup = () => {374 if (context.timeoutId !== undefined) {375 clearTimeout(context.timeoutId);376 context.timeoutId = undefined;377 }378379 if (context.removeExitHandler) {380 context.removeExitHandler();381 }382 };383383 setExitHandler(spawned, parsed.options, context);384 setupTimeout(spawned, parsed.options, context);385386 // TODO: Use native "finally" syntax when targeting Node.js 10388 const processDone = pFinally(handleSpawned(spawned, context), cleanup);387 const processDone = pFinally(handleSpawned(spawned, context), () => {388 cleanup(context);389 });390391 const handlePromise = async () => {392 const [result, stdout, stderr, all] = await getPromiseResult(spawned, parsed.options, processDone);393 result.stdout = handleOutput(parsed.options, stdout);
164 unmodified lines