Instance Method
deactivate(invoking:)
Deactivates the lifecycle.
func deactivate(invoking willResignActive: () async -> Void) async
Parameters
- willResignActive
A callback to run before the lifecycle transitions to inactive. Typically forwards to willResignActive().
Discussion
Idempotent under concurrency: only one caller advances past an internal claim flag, so willResignActive runs at most once per active→inactive transition.
Order of operations:
Atomically claim deactivation under the lock. Concurrent callers that observe isActive == true but isDeactivating == true bail out without running willResignActive.
await willResignActive() while the lifecycle still observes isActive == true.
Under the lock, flip isActive to false, drain the registered task set, and yield false to every subscribed isActiveStream continuation.
Cancel the drained tasks outside the lock (so a misbehaving task cannot deadlock the lifecycle).
Important
The lock is non-recursive. As with activate(invoking:), do not call back into deactivate(invoking:) or activate(invoking:) from inside willResignActive.