(timeout, cb)
| 203 | } |
| 204 | |
| 205 | close(timeout, cb) { |
| 206 | if (typeof timeout === 'function') { |
| 207 | cb = timeout; |
| 208 | timeout = defaults['#close'].timeout; |
| 209 | } else if (!Number.isSafeInteger(timeout) || timeout <= 0) { |
| 210 | timeout = defaults['#close'].timeout; |
| 211 | } |
| 212 | |
| 213 | if (this.paused) { |
| 214 | if (cb) helpers.asCallback(this._closed, cb); |
| 215 | return this._closed; |
| 216 | } |
| 217 | |
| 218 | this.paused = true; |
| 219 | |
| 220 | if (this.checkTimer) { |
| 221 | clearTimeout(this.checkTimer); |
| 222 | this.checkTimer = null; |
| 223 | } |
| 224 | |
| 225 | if (this._delayedTimer) { |
| 226 | this._delayedTimer.stop(); |
| 227 | } |
| 228 | |
| 229 | const drain = () => |
| 230 | helpers.finallyRejectsWithInitial(this._ready, () => { |
| 231 | // Stop the blocking connection, ensures that we don't accept additional |
| 232 | // jobs while waiting for the ongoing jobs to terminate. |
| 233 | if (this.settings.isWorker) { |
| 234 | redis.disconnect(this.bclient); |
| 235 | } |
| 236 | |
| 237 | // Wait for all the jobs to complete. Ignore job errors during shutdown. |
| 238 | return Promise.all( |
| 239 | Array.from(this.activeJobs, (promise) => promise.catch(() => {})) |
| 240 | ).then(() => {}); |
| 241 | }); |
| 242 | |
| 243 | const cleanup = () => { |
| 244 | this._isClosed = true; |
| 245 | |
| 246 | const clients = []; |
| 247 | if (this.client) { |
| 248 | if (this.settings.quitCommandClient) { |
| 249 | clients.push(this.client); |
| 250 | } else { |
| 251 | this.client.removeListener('error', this._emitError); |
| 252 | } |
| 253 | } |
| 254 | if (this.eclient) { |
| 255 | clients.push(this.eclient); |
| 256 | } |
| 257 | |
| 258 | // node_redis' implementation of the QUIT command does not permit it to |
| 259 | // fail. We do not need to consider the case that the quit command aborts. |
| 260 | return Promise.all( |
| 261 | clients.map((client) => helpers.callAsync((done) => client.quit(done))) |
| 262 | ); |
no test coverage detected