Transport Client and Authentication Interceptors in gRPC Swift v2

You're welcome!

Ah yes, good point. Breaking the retain cycle explicitly is my general recommendation for this type of situation anyway.

Rather than hold a reference to the interceptor I would tie its lifetime to the lifetime of the connection by calling nil-ing it out after runConnections() returns/throws:

Task { [gRPCTransportClient] in
    defer { 
        authInterceptor.setAuthClient(authClient: nil) 
    }
    try await gRPCTransportClient.runConnections()
    
}

This is quite a natural place to do it as runConnections() will return when the client has shutdown, you then only need to worry about shutting it down at the appropriate time.

This is the important bit! It's very easy to accidentally introduce a regression because of @unchecked.

1 Like