close
Cancels all background coroutines owned by this instance. Idempotent and thread-safe — safe to call multiple times, from any thread, concurrently.
Exactly one caller wins the latch and calls onClose before cancelling ownJob, giving subclasses a chance to perform synchronous cleanup (e.g. clearing retry maps, releasing resources). Every other caller returns immediately, without waiting for the winner — see the class KDoc on why this is a once barrier rather than a completion barrier.
The parentScope passed at construction is not cancelled — only ownJob and its children are stopped.
A throwing onClose does not strand the instance: ownJob is cancelled from a finally, so the coroutine tree always dies, and the throwable then propagates to the caller (#2330). The latch stays claimed either way — releasing it on a throw would make the hook re-entrant, which is exactly the at-most-once contract onClose states. So a failed hook leaves an instance that is closed and whose failure was reported, never one that is neither open nor closed with no retry.