Skip to content
Myr

Refactor `timeout` option (#294)

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

  • other:+13 added−11 removed

1 file+13 added−11 removed

modified:index.js+13 added-11 removed
323 unmodified lines
324 }325 });326}327328const setupTimeout = (spawned, {timeout, killSignal}, context) => {329 if (timeout > 0) {330 context.timeoutId = setTimeout(() => {331 Object.assign(context, {timeoutId: undefined, timedOut: true});332 spawned.kill(killSignal);333 }, timeout);334 }335};336337const execa = (file, args, options) => {338 const parsed = handleArgs(file, args, options);339 const command = joinCommand(file, args);340
22 unmodified lines
363 spawned.kill();364 });365 }366358 let timeoutId;367 const context = {timedOut: false};368 let isCanceled = false;369370 const cleanup = () => {363 if (timeoutId !== undefined) {364 clearTimeout(timeoutId);365 timeoutId = undefined;371 if (context.timeoutId !== undefined) {372 clearTimeout(context.timeoutId);373 context.timeoutId = undefined;374 }375376 if (removeExitHandler) {377 removeExitHandler();378 }379 };380373 if (parsed.options.timeout > 0) {374 timeoutId = setTimeout(() => {375 timeoutId = undefined;376 context.timedOut = true;377 spawned.kill(parsed.options.killSignal);378 }, parsed.options.timeout);379 }381 setupTimeout(spawned, parsed.options, context);382383 // TODO: Use native "finally" syntax when targeting Node.js 10384 const processDone = pFinally(handleSpawned(spawned, context), cleanup);385
166 unmodified lines