1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-01 16:46:54 +03:00
Files
node-redis/lib/flushAndError.js
Ruben Bridgewater 2b4ab10305 chore - remove standard and use individual config
Standard is not as up to date and still uses a old eslint version.
Instead, use the airbnb default with a couple of modifications.

All required changes are included.
2017-11-28 21:38:21 -02:00

34 lines
1.0 KiB
JavaScript

'use strict'
const Errors = require('redis-errors')
// Flush provided queues, erroring out all items
function flushAndError(client, message, code, options) {
options = options || {}
// Flush the commandQueue first to keep the order intact
const queueNames = options.queues || ['commandQueue', 'offlineQueue']
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 += command.error.stack.replace(/^Error.*?\n/, '\n')
}
if (options.error) {
err.origin = options.error
}
command.callback(err)
}
}
}
module.exports = flushAndError