import Foundation import RastrilloApple /// A `NativePathSource` a test drives by hand: `NativeConnectivity(source:)` /// then sees exactly the path changes the test sends, and none from the /// machine it runs on. public final class ScriptedPathSource: NativePathSource, @unchecked Sendable { private let lock = NSLock() private var update: (@Sendable (NativePath) -> Void)? private var initial: NativePath? /// `initial` is delivered as soon as a connectivity starts, as NWPathMonitor does. public init(_ initial: NativePath.Status? = nil) { self.initial = initial.map { NativePath(status: $0) } } public func start(_ update: @escaping @Sendable (NativePath) -> Void) { let first: NativePath? = lock.withLock { self.update = update; return initial } if let first { update(first) } } public func cancel() { lock.withLock { update = nil } } public func send(_ status: NativePath.Status, isExpensive: Bool = false, isConstrained: Bool = false) { let path = NativePath(status: status, isExpensive: isExpensive, isConstrained: isConstrained) lock.withLock { update }?(path) } }