diff --git a/NucleicRemote/NucleicRemote/Models/HostConnection.swift b/NucleicRemote/NucleicRemote/Models/HostConnection.swift index ab42506..6021e0a 100644 --- a/NucleicRemote/NucleicRemote/Models/HostConnection.swift +++ b/NucleicRemote/NucleicRemote/Models/HostConnection.swift @@ -820,3 +820,17 @@ final class HostConnection { 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 + } +}