Question regarding Clients conforming to Sendable Protocol #1534
-
While going throuch TCA practice apps, I had a question in my mind regarding conformance to Sendable Protocol. One could see that the struct WeatherClient: Sendable {
var forecast: @Sendable (GeocodingSearch.Result) async throws -> Forecast
var search: @Sendable (String) async throws -> GeocodingSearch
} However, other clients of sample apps do not conform to struct AudioPlayerClient {
var play: @Sendable (URL) async throws -> Bool
} struct SpeechClient {
var finishTask: @Sendable () async -> Void
var requestAuthorization: @Sendable () async -> SFSpeechRecognizerAuthorizationStatus
var startTask:
@Sendable (SFSpeechAudioBufferRecognitionRequest) async -> AsyncThrowingStream<
SpeechRecognitionResult, Error
>
enum Failure: Error, Equatable {
case taskError
case couldntStartAudioEngine
case couldntConfigureAudioSession
}
} According to my understanding of Sendable, all structs are implicitly struct WeatherClient {
var forecast: @Sendable (GeocodingSearch.Result) async throws -> Forecast
var search: @Sendable (String) async throws -> GeocodingSearch
} Since all the properties of WeatherClient are sendable, I thought that WeatherClient would implicitly be sendable as well and there would be no need of explicit conformance to If I am mistaken, and that there is a valid reason of differentiating |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hey @inwoodev, you're right, this is mostly an oversight. It could probably be removed, and you're not missing anything special. |
Beta Was this translation helpful? Give feedback.
-
In any case someone stumbles upon this discussion in the future, implicit sendability is only valid at the module's scope (that is |
Beta Was this translation helpful? Give feedback.
Hey @inwoodev, you're right, this is mostly an oversight. It could probably be removed, and you're not missing anything special.
Implicit conformance to
Sendable
is not possible when the value type is generic, or of course when it hosts nonSendable
properties. This is not the case here, andWeatherClient
is implicitlySendable
.