Skip to content

Commit

Permalink
fix: remove retain of self in websocket provider (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
koraykoska committed Mar 24, 2023
1 parent 43ed652 commit 808d6c7
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Sources/FoundationHTTP/Web3WebSocketProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,11 @@ public class Web3WebSocketProvider: Web3Provider, Web3BidirectionalProvider {

private func registerWebSocketListeners() {
// Receive response
webSocket.onText { ws, string in
webSocket.onText { [weak self] ws, string in
guard let self else {
return
}

self.receiveQueue.async {
guard let data = string.data(using: .utf8) else {
return
Expand All @@ -298,7 +302,11 @@ public class Web3WebSocketProvider: Web3Provider, Web3BidirectionalProvider {
}

// Handle close
webSocket.onClose.whenComplete { result in
webSocket.onClose.whenComplete { [weak self] result in
guard let self else {
return
}

if !self.closed && self.webSocket.isClosed {
self.reconnectQueue.asyncAfter(deadline: DispatchTime(uptimeNanoseconds: DispatchTime.now().uptimeNanoseconds + 100_000_000)) {
try? self.reconnect()
Expand Down

0 comments on commit 808d6c7

Please sign in to comment.