Skip to content
Myr

Remove exit handler on exit (#129)

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

authored by Ryan Berdeen · committed by Sindre Sorhus · parent f4e2d56 · Browse files · 2 files+25 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

2 files+25 added−8 removed

  • other:+25 added−8 removed

2 files+25 added−8 removed

modified:index.js+8 added-8 removed
214 unmodified lines
215216 let timeoutId = null;217 let timedOut = false;218219 const cleanupTimeout = () => {219 const cleanup = () => {220 if (timeoutId) {221 clearTimeout(timeoutId);222 timeoutId = null;223 }224225 if (removeExitHandler) {226 removeExitHandler();227 }228 };229230 if (parsed.opts.timeout > 0) {231 timeoutId = setTimeout(() => {
4 unmodified lines
236 }237238 const processDone = new Promise(resolve => {239 spawned.on('exit', (code, signal) => {236 cleanupTimeout();240 cleanup();241 resolve({code, signal});242 });243244 spawned.on('error', err => {241 cleanupTimeout();245 cleanup();246 resolve({error: err});247 });248249 if (spawned.stdin) {250 spawned.stdin.on('error', err => {247 cleanupTimeout();251 cleanup();252 resolve({error: err});253 });254 }255 });
16 unmodified lines
272 const result = arr[0];273 result.stdout = arr[1];274 result.stderr = arr[2];275272 if (removeExitHandler) {273 removeExitHandler();274 }275276 if (result.error || result.code !== 0 || result.signal !== null) {277 const err = makeError(result, {278 joinedCmd,279 parsed,
87 unmodified lines
modified:test.js+17 added
505 unmodified lines
506 await delay(5000);507508 t.is(fs.readFileSync(file, 'utf8'), 'foo\n');509});510511// See #128512test('removes exit handler on exit', async t => {513 // FIXME: This relies on `signal-exit` internals514 const ee = process.__signal_exit_emitter__;515516 const child = m('noop');517 const listener = ee.listeners('exit').pop();518519 await new Promise((resolve, reject) => {520 child.on('error', reject);521 child.on('exit', resolve);522 });523524 const included = ee.listeners('exit').indexOf(listener) !== -1;525 t.false(included);526});