Skip to content
Browse files

Feeble attempt at adding support for domains.

  • Loading branch information...
1 parent 252a77e commit 50e2a6165e74e7d28851aba545495d147047422c @mikeal committed Oct 4, 2012
Showing with 17 additions and 0 deletions.
  1. +2 −0 index.js
  2. +15 −0 test.js
View
2 index.js
@@ -516,6 +516,7 @@ RedisClient.prototype.return_error = function (err) {
// if a callback throws an exception, re-throw it on a new stack so the parser can keep going.
// put this try/catch in its own function because V8 doesn't optimize this well yet.
function try_callback(callback, reply) {
+ if (callback.domain) return callback(null, reply);
try {
callback(null, reply);
} catch (err) {
@@ -641,6 +642,7 @@ function Command(command, args, sub_command, buffer_args, callback) {
this.sub_command = sub_command;
this.buffer_args = buffer_args;
this.callback = callback;
+ if (process.domain) this.callback = process.domain.bind(this.callback)
}
RedisClient.prototype.send_command = function (command, args, callback) {
View
15 test.js
@@ -1592,6 +1592,21 @@ tests.auth = function () {
});
};
+tests.domain = function () {
+ var name = "DOMAIN";
+ var domain = require('domain').create();
+ domain.run(function () {
+ client.set('domain1', 'value', function (e, i) {
+ console.error('throwing')
+ throw new Error('test domain');
+ })
+ })
+ domain.on('error', function (err) {
+ console.error('domain error')
+ next(name);
+ })
+}
+
all_tests = Object.keys(tests);
all_start = new Date();
test_count = 0;

1 comment on commit 50e2a61

@othiym23

I ran into problems getting this to work as well (othiym23/node_redis@66c18aa), and the way I dealt with it was to emit errors in try_callback directly on the domain, when one was active. Doesn't feel right, but it works, and I'm pretty sure it preserves the underlying semantics of letting the parser go about its business without immediately bailing out. We'll see what Isaac makes of my solution.

Please sign in to comment.
Something went wrong with that request. Please try again.