Skip to content

Commit

Permalink
Merge 9cc8ead into 6859aff
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Dec 2, 2016
2 parents 6859aff + 9cc8ead commit 07829bb
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
9 changes: 9 additions & 0 deletions index.js
Expand Up @@ -19,6 +19,15 @@ if (process.__signal_exit_emitter__) {
emitter.emitted = {}
}

// Because this emitter is a global, we have to check to see if a
// previous version of this library failed to enable infinite listeners.
// I know what you're about to say. But literally everything about
// signal-exit is a compromise with evil. Get used to it.
if (!emitter.infinite) {
emitter.setMaxListeners(Infinity)
emitter.infinite = true
}

module.exports = function (cb, opts) {
assert.equal(typeof cb, 'function', 'a callback must be provided for exit handler')

Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -33,6 +33,6 @@
"nyc": "^8.1.0",
"standard": "^7.1.2",
"standard-version": "^2.3.0",
"tap": "^7.1.0"
"tap": "^8.0.1"
}
}
33 changes: 33 additions & 0 deletions test/many-handlers.js
@@ -0,0 +1,33 @@
var onexit = require('../')
var spawn = require('child_process').spawn
var t = require('tap')
var node = process.execPath
var f = __filename

if (process.argv[2] === 'child') {
for (var i = 0; i < 15; i++) {
onexit(function () {
console.log('ok')
})
}
} else {
t.test('parent', function (t) {
var child = spawn(node, [f, 'child'])
var err = ''
var out = ''
var expectOut = new Array(16).join('ok\n')
child.stderr.on('data', function (c) {
err += c
})
child.stdout.on('data', function (c) {
out += c
})
child.on('close', function (code, signal) {
t.equal(code, 0)
t.equal(signal, null)
t.equal(err, '')
t.equal(out, expectOut)
t.end()
})
})
}

0 comments on commit 07829bb

Please sign in to comment.