diff --git a/lib/trycatch.js b/lib/trycatch.js index c0acf88..ddc386a 100755 --- a/lib/trycatch.js +++ b/lib/trycatch.js @@ -57,16 +57,21 @@ function trycatch(tryFn, catchFn) { d.on('error', _trycatchOnError) trycatch.sameTick = true - runInDomain(d, tryFn, trycatchit) + runInDomain(d, tryFn, trycatchit, null, [removeListener]) trycatch.sameTick = false if (isLST) { trycatch.currentStack = parentStack } - return d + return d; + + function removeListener(){ + d.removeListener('error', _trycatchOnError); + } function _trycatchOnError(err) { + removeListener(); err = normalizeError(err) if (OriginalError.stackTraceLimit === 0) err.stack = err.originalStack