Use a Task instead of a DispatchQueue to fix the flakey observation tests. (#4321)

When debugging in, sometimes the value hadn't been set after dispatching, whereas it has with a Task. Not sure I fully understand why and it's annoying that there aren't any observation APIs for didSet.
This commit is contained in:
Doug
2025-07-15 17:58:38 +01:00
committed by GitHub
parent c9375604e1
commit 17000687b5
@@ -20,8 +20,8 @@ extension Observable {
let value = withObservationTracking {
self[keyPath: property]
} onChange: {
// Dispatch the update as this is willSet not didSet.
DispatchQueue.main.async {
// Handle the update on the next run loop as this is willSet not didSet.
Task {
guard isActive else { return }
observe()
}