hummingbird-project / hummingbird

Lightweight, flexible HTTP server framework written in Swift
Apache License 2.0
1.03k stars 51 forks source link

2.x.x - How to disallow `HBResponseBodyWriter` from being used outside `HBResponseBody.write`. #342

Open adam-fowler opened 8 months ago

adam-fowler commented 1 month ago

Can we add a swift 6 conditional conformance to ~Escapable

MahdiBM commented 1 month ago

It appears the consensus around the SwiftNIO team is to use a with...() { } type method for these stuff. See: https://github.com/swift-server/async-http-client/issues/752

(I'm taking a guess at what you mean by this issue, so disregard this comment if what I mentioned is unrelated)

adam-fowler commented 3 weeks ago

@MahdiBM I'm guessing something like this

var writerCopy: ResponseBodyWriter
let response = Response(
    status: .ok, 
    body: .init { writer in
        writerCopy = writer
    }
)
try await writerCopy.write(anotherByteBuffer)