async-exit-hook
async-exit-hook copied to clipboard
Broken API Contract
When calling exit hook, like so:
exitHook(cb => { /* do something on exit */ })
cb may not be a function depending on how the async-exit-hook routine is entered. If it's entered with an uncaught error, then it's called with 2 params and the second is the callback.
if (exit && hook.length > syncArgCount) {
// Hook is async, expects a finish callback
waitingFor++;
if (err) {
// Pass error, calling uncaught exception handlers
return hook(err, stepTowardExit); // call called with 2 params
}
return hook(stepTowardExit); // <-- called with 1 param
}
This would be easy to fix by simply changing the second to:
return hook(null, stepTowardExit);
Because this is a breaking change to the API, it probably warrants a major version upgrade.