You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-01 16:46:54 +03:00
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.
34 lines
1.0 KiB
JavaScript
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
|