Last active
December 11, 2015 01:48
-
-
Save cxreg/4525700 to your computer and use it in GitHub Desktop.
Make node repl work with domains
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/repl.js b/lib/repl.js | |
index ba334cf..1191e9f 100644 | |
--- a/lib/repl.js | |
+++ b/lib/repl.js | |
@@ -113,7 +113,12 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) { | |
} catch (e) { | |
err = e; | |
} | |
- cb(err, result); | |
+ if (err && process.domain) { | |
+ process.domain.emit('error', err); | |
+ process.domain.exit(); | |
+ } | |
+ else | |
+ cb(err, result); | |
}; | |
self.resetContext(); |
It's not possible to check for a domain because the domain may not be entered until the vm.* inside the try/catch. I'll go with the originally proposed version, add a test, and file as a new PR
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Actually, it might be better to just not use the try/catch if there's an active domain ready to catch it.