Skip to content

Commit 2628c8c

Browse files
authored
Prevent memory leaks when passing token getters (#92)
1 parent 783e7a2 commit 2628c8c

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

Sources/SwiftCentrifuge/Client.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public enum CentrifugeError: Error {
2525
case replyError(code: UInt32, message: String, temporary: Bool)
2626
}
2727

28-
public protocol CentrifugeConnectionTokenGetter {
28+
public protocol CentrifugeConnectionTokenGetter: NSObject {
2929
func getConnectionToken(_ event: CentrifugeConnectionTokenEvent, completion: @escaping (Result<String, Error>) -> ())
3030
}
3131

@@ -56,7 +56,7 @@ public struct CentrifugeClientConfig {
5656
public var name = "swift"
5757
public var version = ""
5858
public var token: String = ""
59-
public var tokenGetter: CentrifugeConnectionTokenGetter?
59+
public weak var tokenGetter: CentrifugeConnectionTokenGetter?
6060
public var data: Data? = nil
6161
public var debug: Bool = false
6262
public var logger: CentrifugeLogger?

Sources/SwiftCentrifuge/Subscription.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import Foundation
1010

11-
public protocol CentrifugeSubscriptionTokenGetter {
11+
public protocol CentrifugeSubscriptionTokenGetter: NSObject {
1212
func getSubscriptionToken(_ event: CentrifugeSubscriptionTokenEvent, completion: @escaping (Result<String, Error>) -> ())
1313
}
1414

@@ -33,7 +33,7 @@ public struct CentrifugeSubscriptionConfig {
3333
public var positioned: Bool = false
3434
public var recoverable: Bool = false
3535
public var joinLeave: Bool = false
36-
public var tokenGetter: CentrifugeSubscriptionTokenGetter?
36+
public weak var tokenGetter: CentrifugeSubscriptionTokenGetter?
3737
}
3838

3939
public enum CentrifugeSubscriptionState {

0 commit comments

Comments
 (0)