From afeeff96b1079c43cabbe5906e534778f063ff14 Mon Sep 17 00:00:00 2001 From: Andrew Blakeslee Moore Date: Mon, 6 Jul 2026 13:36:54 -0700 Subject: [PATCH] Network Connection Logic Enhancement Nucleic-Session: 93A70648-2057-4092-9372-860E1BA151D8 Co-authored-by: Nucleic --- .../NucleicRemote/Models/HostConnection.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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 + } +}