From 17000687b5f2bcb48d89e927bb52d3aa705974ec Mon Sep 17 00:00:00 2001 From: Doug <6060466+pixlwave@users.noreply.github.com> Date: Tue, 15 Jul 2025 17:58:38 +0100 Subject: [PATCH] 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. --- ElementX/Sources/Other/Extensions/Observable.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ElementX/Sources/Other/Extensions/Observable.swift b/ElementX/Sources/Other/Extensions/Observable.swift index 248a09a02..1b91cc0d6 100644 --- a/ElementX/Sources/Other/Extensions/Observable.swift +++ b/ElementX/Sources/Other/Extensions/Observable.swift @@ -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() }