Timeout for WebSocket in vapor

Viewed 63

I'm currently connecting to a server using Vapor and WebSocket.

var connectedFuture = WebSocket.connect(to: address, on: app.eventLoopGroup)
do {
    try connectedFuture!.wait()
} catch {
    ...
}

Everything has been working fine. But I've noticed if that connect happens when the container I'm connecting to is restarting, I'm guessing the connection request goes into the void because the socket hangs on that wait command forever, even when the server is back online and listening again.

I can't seem to find any way to cancel the connect, or specificy a timeout for the connect, or the wait.

How would I go about waking this thread back up so it can try and connect again?

0 Answers
Related