-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Description
Use case
I set Strict Concurrency Checking to complete in Xcode 15's Build Settings, and use @MainActor.
Specifically, when implementing a class conforming to a protocol generated by Pigeon, I intend to have a class conforming to @MainActor as a property of that class. I plan to use the functions of that class to perform operations.
Furthermore, in cases where I return a struct defined by Pigeon in a completion handler when implementing functions of the protocol, if the completion handler does not conform to @Sendable, the following warning is issued.
Capture of 'completion' with non-sendable type '(Result<[CustomType], any Error>) -> Void' in a `@Sendable` closure
Proposal
// pigeon generated
// I want to add @Sendable to CustomType
struct CustomType {
var sample1: String
var sample2: Int
}
protocol Sample {
// I want to @Sendable before @escaping
func fetchSample(completion: @escaping (Result<[CustomType], Error>) -> Void)
}
// implements
final class SampleImpl: Sample, Sendable {
private let mainActorSample: MainActorSampleClass = .init()
// I want to @Sendable before @escaping
func fetchSample(completion: @escaping (Result<[CustomType], Error>) -> Void) {
Task { @MainActor in
let customType = mainActorSample.fetchSample()
completion(customType)
}
}
}In practice, even with the aforementioned modifications, a warning is issued at the reply location due to the absence of @Sendable on reply in setMessageHandler.
While it is desirable to eventually address this warning at the reply location, we will exclude it from the scope of consideration in this issue.
The reason is likely that, given the nature of passing arguments to Flutter, it is assumed that reply is implicitly Sendable, and this warning within the code generated by Pigeon can be temporarily ignored.