* Waits for a redis client to be ready. * @param {Redis} redis client
(client)
| 14 | * @param {Redis} redis client |
| 15 | */ |
| 16 | function isRedisReady(client) { |
| 17 | return new Promise((resolve, reject) => { |
| 18 | if (client.status === 'ready') { |
| 19 | resolve(); |
| 20 | } else { |
| 21 | function handleReady() { |
| 22 | client.removeListener('end', handleEnd); |
| 23 | client.removeListener('error', handleError); |
| 24 | resolve(); |
| 25 | } |
| 26 | |
| 27 | let lastError; |
| 28 | function handleError(err) { |
| 29 | lastError = err; |
| 30 | } |
| 31 | |
| 32 | function handleEnd() { |
| 33 | client.removeListener('ready', handleReady); |
| 34 | client.removeListener('error', handleError); |
| 35 | reject(lastError); |
| 36 | } |
| 37 | |
| 38 | client.once('ready', handleReady); |
| 39 | client.on('error', handleError); |
| 40 | client.once('end', handleEnd); |
| 41 | } |
| 42 | }); |
| 43 | } |
| 44 | |
| 45 | module.exports.errorObject = errorObject; |
| 46 | module.exports.tryCatch = tryCatch; |
no test coverage detected
searching dependent graphs…