Network Connection Logic Enhancement

Nucleic-Session: 93A70648-2057-4092-9372-860E1BA151D8
Co-authored-by: Nucleic <[email protected]>
This commit is contained in:
2026-07-06 13:36:54 -07:00
co-authored by Nucleic
parent 1a99d5cae3
commit afeeff96b1
@@ -820,3 +820,17 @@ final class HostConnection {
client = nil client = nil
} }
} }
/// A thread-safe "fire once" latch: the `NWConnection` reachability probe resolves its continuation
/// from a state callback *or* a timeout, on the same queue but from different closures — `take()`
/// returns true to exactly one caller so the continuation is resumed exactly once.
private final class ProbeOnce: @unchecked Sendable {
private let lock = NSLock()
private var done = false
func take() -> Bool {
lock.lock(); defer { lock.unlock() }
if done { return false }
done = true
return true
}
}