To be honest, what I (and others) have wanted is concurrency in NWConnection
I've provided that for myself, with suggestions from this Forum, with the following:
extension NWConnection {
func asyncSend(data: Data?) async throws {
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, Error>) in
send(content: data, completion: .contentProcessed { error in
if let error {
continuation.resume(throwing: error)
} else {
continuation.resume(returning: ())
}
})
}
}
func asyncReceive(length: Int) async throws -> Data {
try await withCheckedThrowingContinuation { continuation in
receive(minimumIncompleteLength: length, maximumLength: length) { data, _, connectionEnded, error in
if connectionEnded {
logger.log("←→ connection did end")
continuation.resume(throwing: NWError.posix(.ECONNRESET))
} else if let error {
continuation.resume(throwing: error)
} else {
continuation.resume(returning: data ?? Data(repeating: 0, count: 4))
}
}
}
}
}
The significantly increased power and sophistication in NetworkConnection
is welcome but my app's networking (with the above Extension
) works from Monterey onwards.
I will file a request in Feedback Assistant .. in fact, I'll file two! One to enhance NWConnection
to support async
and the other to have NetworkConnection
operate in current, and older, systems.
[ FB17963806 ]