Here's a simplified snippet from my project which illustrates the actor context switch for a project value of an @MainActor @Published property:
actor AnActor {
@MainActor @Published public private(set) var allConnected = false
/*
code which sets allConnected not shown
...
*/
// runs in the context of `AnActor`
func waitForAllConnected() async {
// need `await` here as switching context from AnActor to MainActor
// as expected.
if await allConnected {
return
}
// do not need `await $allConnected` as it appears to be in the
// context of AnActor
// UNEXPECTED
for await connected in $allConnected.values {
if connected {
break
}
}
}
}
I would expect the projected value $allConnected
to be in the context of the MainActor however it appears to be in the context of AnActor
- at least that is what the concurrency warning are telling me on Xcode 14.3.
Is my confusion justified or have a missed something?