Skip to content

Commit

Permalink
Use process.nextTick to uncork
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben Bridgewater committed Apr 29, 2016
1 parent a1755b9 commit 340cddb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
5 changes: 3 additions & 2 deletions index.js
Expand Up @@ -437,8 +437,9 @@ RedisClient.prototype.on_ready = function () {
self.pipeline = false;
self.fire_strings = true;
if (self.stream.uncork) {
// TODO: Consider using next tick here. See https://github.com/NodeRedis/node_redis/issues/1033
self.stream.uncork();
process.nextTick(function () {
self.stream.uncork();
});
}
};

Expand Down
4 changes: 3 additions & 1 deletion test/multi.spec.js
Expand Up @@ -674,7 +674,9 @@ describe("The 'multi' method", function () {
// The commands should still be fired, no matter that the socket is destroyed on the same tick
client.multi().set('foo', 'bar').get('foo').exec();
// Abort connection before the value returned
client.stream.destroy();
process.nextTick(function () {
client.stream.destroy();
});
});

it('indivdual commands work properly with multi', function (done) {
Expand Down
8 changes: 6 additions & 2 deletions test/node_redis.spec.js
Expand Up @@ -1112,7 +1112,9 @@ describe('The node_redis client', function () {
}
multi.exec();
assert.equal(client.command_queue_length, 15);
helper.killConnection(client);
process.nextTick(function () {
helper.killConnection(client);
});
});

var end = helper.callFuncAfter(done, 3);
Expand Down Expand Up @@ -1203,7 +1205,9 @@ describe('The node_redis client', function () {
}
multi.exec();
assert.equal(client.command_queue.length, 15);
helper.killConnection(client);
process.nextTick(function () {
helper.killConnection(client);
});
});

var end = helper.callFuncAfter(done, 3);
Expand Down
13 changes: 7 additions & 6 deletions test/pubsub.spec.js
Expand Up @@ -491,18 +491,19 @@ describe('publish/subscribe', function () {
});
sub2.on('ready', function () {
sub2.batch().psubscribe('*', helper.isString('*')).exec();
sub2.subscribe('/foo');
sub2.subscribe('/foo', function () {
pub.pubsub('numsub', '/foo', function (err, res) {
assert.deepEqual(res, ['/foo', 2]);
});
// sub2 is counted twice as it subscribed with psubscribe and subscribe
pub.publish('/foo', 'hello world', helper.isNumber(3));
});
sub2.on('pmessage', function (pattern, channel, message) {
assert.strictEqual(pattern.inspect(), new Buffer('*').inspect());
assert.strictEqual(channel.inspect(), new Buffer('/foo').inspect());
assert.strictEqual(message.inspect(), new Buffer('hello world').inspect());
sub2.quit(done);
});
pub.pubsub('numsub', '/foo', function (err, res) {
assert.deepEqual(res, ['/foo', 2]);
});
// sub2 is counted twice as it subscribed with psubscribe and subscribe
pub.publish('/foo', 'hello world', helper.isNumber(3));
});
});

Expand Down

0 comments on commit 340cddb

Please sign in to comment.