Hi everyone,
I am having an issue where I want to have a synchronous method taking a non sendable value that I want to use in an actor and as of now cannot understand why I cannot do it/how to do it. If the handle method is async, it works.
Testing the following code in a new Swift Package with swiftLanguageModes: [.v6]
final class NonSendable { }
@available(iOS 13.0, *)
actor TestActor {
func store(nonSendable: sending NonSendable) { }
}
@available(macOS 10.15, *)
@available(iOS 13.0, *)
func handle(nonSendable: sending NonSendable) {
let actor = TestActor()
Task {
await actor.store(nonSendable: nonSendable) // Sending task-isolated 'nonSendable' to actor-isolated instance method 'store(nonSendable:)' risks causing data races between actor-isolated and task-isolated uses
}
}
@available(macOS 10.15, *)
@available(iOS 13.0, *)
func testUsage() {
let nonSendable = NonSendable()
handle(nonSendable: nonSendable)
// handle(nonSendable: nonSendable) // This should be prevented - and is, stops compiling
}
Would appreciate any help. Of course, creating a Sendable box works, but I would like to find a correct solution without having to resort to that - if possible.