1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-04 15:02:09 +03:00

chore: refactor some code and remove obsolete variable

This commit is contained in:
Ruben Bridgewater
2017-05-28 05:21:42 +02:00
parent 39da7878d4
commit 579e080ad5
7 changed files with 62 additions and 57 deletions

32
lib/flushAndError.js Normal file
View File

@@ -0,0 +1,32 @@
'use strict'
const Errors = require('redis-errors')
// Flush provided queues, erroring any items with a callback first
function flushAndError (client, message, code, options) {
options = options || {}
const queueNames = options.queues || ['commandQueue', 'offlineQueue'] // Flush the commandQueue first to keep the order intact
for (var i = 0; i < queueNames.length; i++) {
// If the command was fired it might have been processed so far
const ErrorClass = queueNames[i] === 'commandQueue'
? Errors.InterruptError
: Errors.AbortError
while (client[queueNames[i]].length) {
const command = client[queueNames[i]].shift()
const err = new ErrorClass(message)
err.code = code
err.command = command.command.toUpperCase()
err.args = command.args
if (command.error) {
err.stack = err.stack + command.error.stack.replace(/^Error.*?\n/, '\n')
}
if (options.error) {
err.origin = options.error
}
command.callback(err)
}
}
}
module.exports = flushAndError