Skip to content
Myr

Simplify code related to `context` (#310)

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 c2787e5 · Browse files · 1 file+8 added−8 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+8 added−8 removed

  • other:+8 added−8 removed

1 file+8 added−8 removed

modified:index.js+8 added-8 removed
325 unmodified lines
326};327328const setupTimeout = (spawned, {timeout, killSignal}, context) => {329 if (timeout > 0) {330 context.timeoutId = setTimeout(() => {331 Object.assign(context, {timeoutId: undefined, timedOut: true});330 return setTimeout(() => {331 context.timedOut = true;332 spawned.kill(killSignal);333 }, timeout);334 }335};336337// #115338const setExitHandler = (spawned, {cleanup, detached}, context) => {338const setExitHandler = (spawned, {cleanup, detached}) => {339 if (!cleanup || detached) {340 return;341 }342343 context.removeExitHandler = onExit(() => {343 return onExit(() => {344 spawned.kill();345 });346};347348const cleanup = ({timeoutId, removeExitHandler}) => {348const cleanup = (timeoutId, removeExitHandler) => {349 if (timeoutId !== undefined) {350 clearTimeout(timeoutId);351 }352
26 unmodified lines
379380 const context = {timedOut: false};381 let isCanceled = false;382383 setExitHandler(spawned, parsed.options, context);384 setupTimeout(spawned, parsed.options, context);383 const timeoutId = setupTimeout(spawned, parsed.options, context);384 const removeExitHandler = setExitHandler(spawned, parsed.options);385386 // TODO: Use native "finally" syntax when targeting Node.js 10387 const processDone = pFinally(handleSpawned(spawned, context), () => {388 cleanup(context);388 cleanup(timeoutId, removeExitHandler);389 });390391 const handlePromise = async () => {392 const [result, stdout, stderr, all] = await getPromiseResult(spawned, parsed.options, processDone);
165 unmodified lines