                 unwrappedConnection.delegate?.connectionDidReconnect()
             } else {
                 unwrappedConnection.logger.log(logLevel: .debug, message: "Internal error - unexpected connection state")
-                // TODO: stop with error?
-                // use dispatchGroup to block stop while reconnecting/starting
+                // TODO: consider using dispatchGroup to block stop while reconnecting/starting.
             }
         }
 

                connection?.restartConnection(error: error)
            } else {
                unwrappedConnection.logger.log(logLevel: .debug, message: "Assuming clean stop - stopping connection")
                if  unwrappedConnection.state == .stopping {
                    _ = unwrappedConnection.changeState(from: [.stopping], to: .disconnected)
                    unwrappedConnection.delegate?.connectionDidClose(error: error)
                } else {
                    // TODO: Review what happens if this close happens when the connection is
                    // in one of these states:
                    //  - starting (possible?)
                    //  - reconnecting
                    //  - disconnected (possible?)
                    unwrappedConnection.logger.log(logLevel: .error, message: "Internal error - unexpected state")
                }
            }
        }
    }


internal class ReconnectableConnection: Connection {
    private let connectionQueue = DispatchQueue(label: "SignalR.reconnection.queue")

    private let connectionFactory: () -> Connection
    private let reconnectPolicy: ReconnectPolicy
