@@ -135,6 +135,35 @@ public final actor HTTPServer {
135135 }
136136
137137 private func listenForConnections( on socket: AsyncSocket ) async throws {
138+ #if compiler(>=5.9)
139+ if #available( macOS 14 . 0 , iOS 16 . 4 , tvOS 16 . 4 , * ) {
140+ try await listenForConnectionsDiscarding ( on: socket)
141+ } else {
142+ try await listenForConnectionsFallback ( on: socket)
143+ }
144+ #else
145+ try await listenForConnectionsFallback ( on: socket)
146+ #endif
147+ }
148+
149+ #if compiler(>=5.9)
150+ @available ( macOS 14 . 0 , iOS 16 . 4 , tvOS 16 . 4 , * )
151+ private func listenForConnectionsDiscarding( on socket: AsyncSocket ) async throws {
152+ try await withThrowingDiscardingTaskGroup { [ logger] group in
153+ for try await socket in socket. sockets {
154+ group. addTask {
155+ await self . handleConnection ( HTTPConnection ( socket: socket, logger: logger) )
156+ }
157+ }
158+ }
159+ throw SocketError . disconnected
160+ }
161+ #endif
162+
163+ @available ( macOS, deprecated: 14.0 , renamed: " listenForConnectionsDiscarding(on:) " )
164+ @available ( iOS, deprecated: 16.4 , renamed: " listenForConnectionsDiscarding(on:) " )
165+ @available ( tvOS, deprecated: 16.4 , renamed: " listenForConnectionsDiscarding(on:) " )
166+ private func listenForConnectionsFallback( on socket: AsyncSocket ) async throws {
138167 try await withThrowingTaskGroup ( of: Void . self) { [ logger] group in
139168 for try await socket in socket. sockets {
140169 group. addTask {
0 commit comments