[swift-server-dev] HTTP API v0.1.0
Johannes Weiß
johannesweiss at apple.com
Mon Nov 6 12:20:57 CST 2017
Hi Helge,
Why not a
protocol HTTPRequestHandling {
associatedtype Context
}
then an implementation that uses DispatchQueues can make `typealias Context = DispatchQueue` or whatever it feels like?
-- Johannes
> On 5 Nov 2017, at 3:26 pm, Helge Heß via swift-server-dev <swift-server-dev at swift.org> wrote:
>
> On 2. Nov 2017, at 21:23, Johannes Weiß <johannesweiss at apple.com> wrote:
>>> Yes. But unlike a) and b), this requires that the handler gets the queue it is running on, so that it can do:
>>>
>>> func handler(req, res, queue httpQueue:…) {
>>> bgQueue.async {
>>> // very very very expensive work, like doing an Animoji
>>> // done with it,
>>> httpQueue.async(doneCallback)
>>> }
>>> }
>>>
>>> If you get the point.
>>
>> yes, agreed.
>
> I pushed this:
>
> https://github.com/swift-server/http/pull/86
>
> Take this as a point for discussion. I chose to pass in an optional DispatchQueue (sync servers would pass in nil). It could also be a non-optional protocol which DispatchQueue implements.
>
> I also attached specific semantics:
> - the handler is called on the queue which is passed in
> - hence callbacks don’t need synchronisation if they stay on the queue
>
> Maybe the protocol variant is better, but I wanted to avoid an additional HTTPSynchronizationContext protocol if possible. And my proposal works OK for both sync and async (but not for other async options like uv).
>
> hh
>
> _______________________________________________
> swift-server-dev mailing list
> swift-server-dev at swift.org
> https://lists.swift.org/mailman/listinfo/swift-server-dev
More information about the swift-server-dev
mailing list