Created
October 22, 2024 20:57
-
-
Save simonnickel/4d8d1ffd3f5d98482fbc293b0a11b8a1 to your computer and use it in GitHub Desktop.
Swift Actor - later accesses could race
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
actor SomeActor { | |
func doSomething() { } | |
} | |
class SomeClass { | |
private let someActor = SomeActor() | |
func doSomething() { | |
Task { // Task-isolated value of type '() async -> ()' passed as a strongly transferred parameter; later accesses could race | |
await someActor.doSomething() | |
} | |
} | |
func doSomething() async { | |
await someActor.doSomething() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is tricky because the compiler error is really unhelpful. Here's what's going on:
this is actually:
You are catpuring self in a non-isolated task, but self (
SomeClass
) is not Sendable! Even this will not work.To do what you want, to have to avoid the
self
capture. Perhaps like this: