Closed pfandrade closed 3 years ago
Hi, can you point to the specific documentation you're referring to? I'm a little unclear on what scenario this pull request is attempting to resolve?
It's actually in the code itself. Docs don't mention it but there's an exception logged in the Xcode console on a second call to reconnect. And it's not just the log message, apparently it actually doesn't reconnect. Creating a new connection works however.
Ah ok that makes sense now.
However, I think rather than making the change you've currently proposed I'd prefer that any calls to connect()
should only initialise the connection
and then configure it if the object is nil
. This should work since the connection
object is set to nil
in the stopConnection(error:)
method (which is called as a result of a either server or client-triggered disconnections):
open func connect() {
if connection == nil {
connection = NWConnection(to: endpoint, using: parameters)
intentionalDisconnect = false
connection?.stateUpdateHandler = stateDidChange(to:)
listen()
connection?.start(queue: connectionQueue)
}
}
There's a related task here that the code comment docs for the connect()
method of WebSocketConnection
should probably reflect this behaviour.
Closing since there have been several reconnection improvements included in the 0.5.0 release.
Notably this includes ensuring that subsequent calls to connect()
have no effect.
As per documentation a connection should only receiver a start call once.