Skip to content

Commit 227beb8

Browse files
committed
PR review: Use non throwing task group.
1 parent 8dbb961 commit 227beb8

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

Sources/NIOPosix/Bootstrap.swift

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -686,17 +686,29 @@ extension ServerBootstrap {
686686

687687
try await withTaskCancellationHandler {
688688
try await channel.executeThenClose { inbound, outbound in
689-
try await withThrowingDiscardingTaskGroup { group in
690-
try await channel.executeThenClose { inbound in
691-
for try await connectionChannel in inbound {
692-
group.addTask {
693-
try await connectionChannel.executeThenClose { _, _ in
694-
try await onConnection(connectionChannel)
689+
// we need to dance the result dance here, since we can't throw from the
690+
// withDiscardingTaskGroup closure.
691+
let result = await withDiscardingTaskGroup { group -> Result<Void, any Error> in
692+
do {
693+
try await channel.executeThenClose { inbound in
694+
for try await connectionChannel in inbound {
695+
group.addTask {
696+
do {
697+
try await connectionChannel.executeThenClose { _, _ in
698+
try await onConnection(connectionChannel)
699+
}
700+
} catch {
701+
// ignore single connection failures?
702+
}
695703
}
696704
}
697705
}
706+
return .success(())
707+
} catch {
708+
return .failure(error)
698709
}
699710
}
711+
try result.get()
700712
}
701713
} onCancel: {
702714
channel.channel.close(promise: nil)

0 commit comments

Comments
 (0)