Skip to content

Commit a8301df

Browse files
authored
Merge pull request #60 from swhitty/swift-5.9
DiscardingTaskGroup
2 parents 7cfff2f + 4f0e6c4 commit a8301df

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

FlyingFox/Sources/HTTPServer.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 {

docker-run-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ set -eu
55
docker run -it \
66
--rm \
77
--mount src="$(pwd)",target=/flyingfox,type=bind \
8-
swift \
8+
swiftlang/swift:nightly-5.9-jammy \
99
/usr/bin/swift test --package-path /flyingfox

0 commit comments

Comments
 (0)