From b837b46e762129c9f5ccf4eddaa37d6e92d394a9 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sun, 28 May 2017 04:32:29 +0200 Subject: [PATCH] chore: use short handle for process.nextTick --- index.js | 6 ++++-- lib/readyHandler.js | 6 +++--- lib/utils.js | 4 +--- test/connection.spec.js | 8 ++------ test/helper.js | 2 +- test/lib/good-traces.js | 8 ++------ test/node_redis.spec.js | 10 ++++------ 7 files changed, 17 insertions(+), 27 deletions(-) diff --git a/index.js b/index.js index 7e4f50e130..e8db5521e4 100644 --- a/index.js +++ b/index.js @@ -67,8 +67,10 @@ function RedisClient (options, stream) { options.detectBuffers = !!options.detectBuffers // Override the detectBuffers setting if returnBuffers is active and print a warning if (options.returnBuffers && options.detectBuffers) { - process.nextTick(() => - utils.warn(this, 'WARNING: You activated returnBuffers and detectBuffers at the same time. The return value is always going to be a buffer.') + process.nextTick( + utils.warn, + this, + 'WARNING: You activated returnBuffers and detectBuffers at the same time. The return value is always going to be a buffer.' ) options.detectBuffers = false } diff --git a/lib/readyHandler.js b/lib/readyHandler.js index ed23061984..022b310274 100644 --- a/lib/readyHandler.js +++ b/lib/readyHandler.js @@ -57,14 +57,14 @@ function readyHandler (client) { if (!client.closing) { // TODO: These internal things should be wrapped in a // special error that describes what is happening - process.nextTick(() => client.emit('error', err)) + process.nextTick(client.emit, 'error', err) } }) } if (client.monitoring) { // Monitor has to be fired before pub sub commands client.internalSendCommand(new Command('monitor', [])).catch((err) => { if (!client.closing) { - process.nextTick(() => client.emit('error', err)) + process.nextTick(client.emit, 'error', err) } }) } @@ -86,7 +86,7 @@ function readyHandler (client) { const args = client.subscriptionSet[key] client[command]([args]).catch((err) => { if (!client.closing) { - process.nextTick(() => client.emit('error', err)) + process.nextTick(client.emit, 'error', err) } }) } diff --git a/lib/utils.js b/lib/utils.js index af5b6285b4..dc2221602f 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -103,9 +103,7 @@ function replyInOrder (client, callback, err, res, queue) { commandObj = client.offlineQueue.peekBack() || client.commandQueue.peekBack() } if (!commandObj) { - process.nextTick(() => { - callback(err, res) - }) + process.nextTick(callback, err, res) } else { const tmp = commandObj.callback commandObj.callback = function (e, r) { diff --git a/test/connection.spec.js b/test/connection.spec.js index 5c4ea7a74c..6ef925bedf 100644 --- a/test/connection.spec.js +++ b/test/connection.spec.js @@ -127,9 +127,7 @@ describe('connection tests', () => { client.once('ready', () => { client.set('foo', 'bar').catch(helper.isError()) client.quit().then(() => done()) - process.nextTick(() => { - client._stream.destroy() - }) + process.nextTick(() => client._stream.destroy()) }) }) }) @@ -288,9 +286,7 @@ describe('connection tests', () => { client = redis.createClient({ connectTimeout: 1000 }) - process.nextTick(() => { - assert.strictEqual(client._stream._idleTimeout, 1000) - }) + process.nextTick(assert.strictEqual, client._stream._idleTimeout, 1000) client.on('connect', () => { assert.strictEqual(client._stream._idleTimeout, -1) assert.strictEqual(client._stream.listeners('timeout').length, 0) diff --git a/test/helper.js b/test/helper.js index 47d2f10338..01cc678e1c 100644 --- a/test/helper.js +++ b/test/helper.js @@ -207,6 +207,6 @@ module.exports = { family: 4 } client.address = '127.0.0.1:65535' - client._stream.destroy() + process.nextTick(() => client._stream.destroy()) } } diff --git a/test/lib/good-traces.js b/test/lib/good-traces.js index 832f5a85bd..3f52b888ad 100644 --- a/test/lib/good-traces.js +++ b/test/lib/good-traces.js @@ -10,11 +10,7 @@ client.set('foo').catch((err) => { assert(/good-traces.js:9:8/.test(err.stack)) client.set('foo', 'bar').catch((err) => { assert(/good-traces.js:11:10/.test(err.stack)) - client.quit(() => { - process.exit(0) - }) - }) - process.nextTick(() => { - client._stream.destroy() + client.quit(() => process.exit(0)) }) + process.nextTick(() => client._stream.destroy()) }) diff --git a/test/node_redis.spec.js b/test/node_redis.spec.js index 89d1a63dd8..8b809eb0e5 100644 --- a/test/node_redis.spec.js +++ b/test/node_redis.spec.js @@ -476,12 +476,10 @@ describe('The nodeRedis client', () => { assert(err instanceof redis.InterruptError) error = err.origin }) - // Make sure we call execute out of the reply - // ready is called in a reply - process.nextTick(() => { - // Fail the set answer. Has no corresponding command obj and will therefore land in the error handler and set - client._replyParser.execute(Buffer.from('a*1\r*1\r$1`zasd\r\na')) - }) + // Make sure we call execute out of the reply. + // Ready is called in a reply. + // Fail the set answer. Has no corresponding command obj and will therefore land in the error handler and set + process.nextTick(() => client._replyParser.execute(Buffer.from('a*1\r*1\r$1`zasd\r\na'))) }) }) })