async-exit-hook icon indicating copy to clipboard operation
async-exit-hook copied to clipboard

Broken API Contract

Open sjones6 opened this issue 6 years ago • 0 comments

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.

sjones6 avatar Apr 05 '19 15:04 sjones6