Skip to content

Commit

Permalink
reconnect when back from background
Browse files Browse the repository at this point in the history
  • Loading branch information
terhechte committed Jul 22, 2022
1 parent 630bf01 commit 566549b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Sources/SwiftGraphQL/HTTP+WebSockets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,17 @@ public class GraphQLSocket<S: GraphQLEnabledSocket> {
errorHandler: @escaping (Error) -> Void
) {
if state == .notRunning {
// In this case we probably came back from the background, try to connect again
start(connectionParams: lastConnectionParams, errorHandler: errorHandler)
DispatchQueue.global(qos: .utility).asyncAfter(deadline: .now() + 2.0) { [weak self] in
self?.detachedPingQueue(interval: interval, errorHandler: errorHandler)
}
return
}
DispatchQueue.global(qos: .utility).asyncAfter(deadline: .now() + interval) { [weak self] in
guard let self = self else { return }
guard let self = self else {
return
}
do {
let message = Message.ping()
let messageData = try self.encoder.encode(message)
Expand Down

0 comments on commit 566549b

Please sign in to comment.