From 9eb7fea4bdd3e873e2afd3f326bcd9ffc726d576 Mon Sep 17 00:00:00 2001 From: Pierre Jansen Date: Tue, 8 Dec 2015 18:22:49 +0200 Subject: [PATCH] Added cleaning up of listener resources --- lib/trycatch.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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