Skip to content
Myr

Improve/refactor `.cancel()` (#309)

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

  • other:+12 added−11 removed

1 file+12 added−11 removed

modified:index.js+12 added-11 removed
300 unmodified lines
301302 return forceKillAfterTimeout;303};304305const spawnedCancel = (spawned, context) => {306 const killResult = spawned.kill();307308 if (killResult) {309 context.isCanceled = true;310 }311};312313const handleSpawned = (spawned, context) => {314 return new Promise((resolve, reject) => {315 spawned.on('exit', (code, signal) => {316 if (context.timedOut) {
64 unmodified lines
381 }))382 );383 }384377 const kill = spawned.kill.bind(spawned);378 spawned.kill = spawnedKill.bind(null, kill);385 const context = {timedOut: false, isCanceled: false};386380 const context = {timedOut: false};381 let isCanceled = false;387 spawned.kill = spawnedKill.bind(null, spawned.kill.bind(spawned));388 spawned.cancel = spawnedCancel.bind(null, spawned, context);389390 const timeoutId = setupTimeout(spawned, parsed.options, context);391 const removeExitHandler = setExitHandler(spawned, parsed.options);392
13 unmodified lines
406 code: result.code,407 command,408 parsed,409 timedOut: context.timedOut,403 isCanceled,410 isCanceled: context.isCanceled,411 killed: spawned.killed412 });413414 if (!parsed.options.reject) {
22 unmodified lines
437 handleInput(spawned, parsed.options.input);438439 spawned.all = makeAllStream(spawned);440434 spawned.cancel = () => {435 if (spawned.kill()) {436 isCanceled = true;437 }438 };439441 return mergePromise(spawned, handlePromise);442};443444module.exports = execa;
114 unmodified lines