Skip to content

Commit

Permalink
DiscardingTaskGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
swhitty committed Jun 8, 2023
1 parent 7cfff2f commit d50f36e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
29 changes: 29 additions & 0 deletions FlyingFox/Sources/HTTPServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,35 @@ public final actor HTTPServer {
}

private func listenForConnections(on socket: AsyncSocket) async throws {
#if compiler(>=5.9)
if #available(macOS 14.0, iOS 17.0, tvOS 17.0, *) {
try await listenForConnectionsDiscarding(on: socket)
} else {
try await listenForConnectionsFallback(on: socket)
}
#else
try await listenForConnectionsFallback(on: socket)
#endif
}

#if compiler(>=5.9)
@available(macOS 14.0, iOS 17.0, tvOS 17.0, *)
private func listenForConnectionsDiscarding(on socket: AsyncSocket) async throws {
try await withThrowingDiscardingTaskGroup { [logger] group in
for try await socket in socket.sockets {
group.addTask {
await self.handleConnection(HTTPConnection(socket: socket, logger: logger))
}
}
}
throw SocketError.disconnected
}
#endif

@available(macOS, deprecated: 14.0, renamed: "listenForConnectionsDiscarding(on:)")
@available(iOS, deprecated: 17.0, renamed: "listenForConnectionsDiscarding(on:)")
@available(tvOS, deprecated: 17.0, renamed: "listenForConnectionsDiscarding(on:)")
private func listenForConnectionsFallback(on socket: AsyncSocket) async throws {
try await withThrowingTaskGroup(of: Void.self) { [logger] group in
for try await socket in socket.sockets {
group.addTask {
Expand Down
2 changes: 1 addition & 1 deletion docker-run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ set -eu
docker run -it \
--rm \
--mount src="$(pwd)",target=/flyingfox,type=bind \
swift \
swiftlang/swift:nightly-5.9-jammy \
/usr/bin/swift test --package-path /flyingfox

0 comments on commit d50f36e

Please sign in to comment.