(self)
| 197 | } |
| 198 | |
| 199 | export function closeHandler(self) { |
| 200 | return function () { |
| 201 | const prevStatus = self.status; |
| 202 | self.setStatus("close"); |
| 203 | |
| 204 | if (self.commandQueue.length) { |
| 205 | abortIncompletePipelines(self.commandQueue); |
| 206 | } |
| 207 | if (self.offlineQueue.length) { |
| 208 | abortTransactionFragments(self.offlineQueue); |
| 209 | } |
| 210 | |
| 211 | if (prevStatus === "ready") { |
| 212 | if (!self.prevCondition) { |
| 213 | self.prevCondition = self.condition; |
| 214 | } |
| 215 | if (self.commandQueue.length) { |
| 216 | self.prevCommandQueue = self.commandQueue; |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | if (self.manuallyClosing) { |
| 221 | self.manuallyClosing = false; |
| 222 | debug("skip reconnecting since the connection is manually closed."); |
| 223 | return close(); |
| 224 | } |
| 225 | |
| 226 | if (typeof self.options.retryStrategy !== "function") { |
| 227 | debug("skip reconnecting because `retryStrategy` is not a function"); |
| 228 | return close(); |
| 229 | } |
| 230 | const retryDelay = self.options.retryStrategy(++self.retryAttempts); |
| 231 | |
| 232 | if (typeof retryDelay !== "number") { |
| 233 | debug( |
| 234 | "skip reconnecting because `retryStrategy` doesn't return a number" |
| 235 | ); |
| 236 | return close(); |
| 237 | } |
| 238 | |
| 239 | debug("reconnect in %sms", retryDelay); |
| 240 | |
| 241 | self.setStatus("reconnecting", retryDelay); |
| 242 | self.reconnectTimeout = setTimeout(function () { |
| 243 | self.reconnectTimeout = null; |
| 244 | self.connect().catch(noop); |
| 245 | }, retryDelay); |
| 246 | |
| 247 | const { maxRetriesPerRequest } = self.options; |
| 248 | if (typeof maxRetriesPerRequest === "number") { |
| 249 | if (maxRetriesPerRequest < 0) { |
| 250 | debug("maxRetriesPerRequest is negative, ignoring..."); |
| 251 | } else { |
| 252 | const remainder = self.retryAttempts % (maxRetriesPerRequest + 1); |
| 253 | if (remainder === 0) { |
| 254 | debug( |
| 255 | "reach maxRetriesPerRequest limitation, flushing command queue..." |
| 256 | ); |
nothing calls this directly
no test coverage detected
searching dependent graphs…