[swift-server-dev] Next HTTP API meeting

Helge Heß me at helgehess.eu
Mon Mar 27 16:22:50 CDT 2017

On 27 Mar 2017, at 23:08, Sergo Beruashvili via swift-server-dev <swift-server-dev at swift.org> wrote:
> Hello everyone,
> I think we are missing something here,
> If we use struct for Request/Response, this means we cannot use them in @escaping closures.

You can use structs in @escaping closures just fine. You just can’t use inout for obvious reasons.

Still good that you mention this.

> Most of requests end up reading from a database ( redis, mysql/postgre... ) or maybe even from a network.
> Proper way of reading from those sources would be using DispatchIO ( or similar technique ) , which does not block the current execution, but reads the data and calls your @escaping closure once its done.

This has the assumption that data must be fed using closures, that certainly doesn’t have to be the case and should probably be the concern of the web framework. Escaping closures can be convenient (unless you go crazy w/ the ref cycles), but do have a non-negligible performance impact! Kinda like the most expensive way to do callbacks ...

BTW: the async IO you talk about is mostly done on the body stream (hence chunked I/O and trailing headers …). The stream obviously has to be a reference type.


More information about the swift-server-dev mailing list