I tried the following using May 14, 2025 toolchain:
@Observable
class Model {
var count = 0
}
extension Model {
@MainActor static var shared = Model()
}
@MainActor
func startModelObservation() {
print(#function)
let values = Observations { Model.shared.count }
if #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) {
Task.immediate {
for await value in values {
print("Fresh value: \(value)")
}
}
}
}
func doSomethingElse() {
print(#function)
}
startModelObservation()
doSomethingElse()
Prints:
startModelObservation()
Fresh value: 0
doSomethingElse()