[swift-server-dev] HTTP API v0.1.0

Helge Heß me at helgehess.eu
Sun Nov 5 17:26:28 CST 2017


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 874 bytes
Desc: Message signed with OpenPGP
URL: <https://lists.swift.org/pipermail/swift-server-dev/attachments/20171106/ea5b0f57/attachment.sig>


More information about the swift-server-dev mailing list