Skip to content

Instantly share code, notes, and snippets.

@cxreg
Last active December 11, 2015 01:48
Show Gist options
  • Save cxreg/4525700 to your computer and use it in GitHub Desktop.
Save cxreg/4525700 to your computer and use it in GitHub Desktop.
Make node repl work with domains
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();
@cxreg
Copy link
Author

cxreg commented Jan 19, 2013

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