Repository navigation
Conversation
|
This PR as is adds a lot of code to impelement conformance to a bad comment. The comment was originally true to fact before the The AI read this comment as a contract and assumed it needed to fix it, adding even more complexity (another dispatch and a bunch of tests), even though all the code was working. Two wrongs don't make a right. I would like to clean this up; with async we can avoid much of the hopping around and have a simpler protocol. One async method instead of a requirement, a helper and a default, with no queue hopping in the deletion path. The pumpManager protocol could also use the protocol simplification. The cleanup will affect a lot of repos, but the changes should be small, and generally simplify code in the pump/cgm implementations as well. |
CGMManager.delete() and PumpManager.delete() are now async and return once the delegate has removed the manager. They replace delete(completion:), notifyDelegateOfDeletion, prepareForDeactivation and notifyDelegateOfDeactivation, so the deletion cycle no longer hops through the delegate queue or mixes completion handlers with async code. PumpManagerDelegate.pumpManagerWillDeactivate becomes pumpManagerWantsDeletion(_:) async, matching cgmManagerWantsDeletion. A manager that tears down first awaits that teardown, including alert retractions, before awaiting the delegate, which orders retractions ahead of deletion (#675). Supersedes #680 (fixes #676).
CGMManager.notifyDelegateOfDeletion(completion:)is documented to call its completion from the delegate queue, but sincecgmManagerWantsDeletionbecame async the completion runs inside theTaskon whatever executor resumes it. Callers that rely on the delegate queue (as they still can withPumpManager.notifyDelegateOfDeactivation) get the completion on an arbitrary thread. This hops back todelegateQueueafter the delegate call returns.notifyDelegateOfDeletionnow dispatchescompletionontodelegateQueueafter awaitingcgmManagerWantsDeletion.CGMManagerTestswith a minimal CGM manager and delegate that checks completion runs on the configured delegate queue and only aftercgmManagerWantsDeletionwas called. The test fails without the change (completion runs off the delegate queue) and passes with it.LoopKitTestson an iOS 26.5 simulator against LoopAlgorithm 3965100 (the last commit with publicLoopQuantity; LoopAlgorithm main at 41baa8f no longer builds with next-dev).Kit authors: G7SensorKit's
delete()relies on its alert retractions being ordered ahead of the deletion notification. Kits should await their retractions before callingnotifyDelegateOfDeletion(see #675). No kits are changed here.Fixes #676