Network Connection Logic Enhancement
Nucleic-Session: 93A70648-2057-4092-9372-860E1BA151D8 Co-authored-by: Nucleic <[email protected]>
This commit is contained in:
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user