i have some code that is relying on unstructured tasks to send the right task cancellation signals into some async
-colored code.
try await stream.frames.executeThenClose
{
(
inbound:NIOAsyncChannelInboundStream<HTTP2Frame.FramePayload>,
outbound:NIOAsyncChannelOutboundWriter<HTTP2Frame.FramePayload>
) in
let request:Task<ServerResponse, any Error> = .init
{
try await self.respond(to: inbound)
}
stream.frames.channel.closeFuture.whenComplete
{
_ in request.cancel()
}
let message:ServerMessage
do
{
message = .init(response: try await request.value)
}
catch let error
{
message = .init(redacting: error)
}
try await outbound.send(message)
}
but since this is relying on unstructured tasks i wondered if there was a better way to achieve this with structured concurrency.