centrifugal / centrifuge-swift

Swift client SDK for bidirectional real-time communication with Centrifugo and Centrifuge-based server over WebSocket
MIT License
47 stars 41 forks source link

Mark `refresh` and `private sub` completion blocks as escaping #17

Closed fedulvtubudul closed 4 years ago

fedulvtubudul commented 4 years ago

Having these blocks marked as escaping is essential if the CentrifugeClientDelegate implementation calls them not "inline" but asynchronously, which is the case for most real-life situations.

In our case the delegate makes an async call to REST authorization service to provide fresh tokens:

func onRefresh(_ client: CentrifugeClient, _ event: CentrifugeRefreshEvent,
    completion: @escaping (_ token: String) -> Void) {

    DDLogInfo("Centrifuge requested to refresh the token...", level: logLevel)

    self.requestCredentials(for: .user) { (credential) in
        completion(credential.token)
    }
}

As requestCredentials method is async and escapes it's completion block, the completion of onRefresh escapes as well.

fedulvtubudul commented 4 years ago

I've had to explicitly define Starscream dependency version, because it was updated recently and the latest version is not compatible anymore.

FZambia commented 4 years ago

@fedulvtubudul thanks! Will try to make new release as soon as I have some time - hopefully later today or tomorrow

FZambia commented 4 years ago

@fedulvtubudul just released 0.0.4 with these changes