[swift-server-dev] Next HTTP API meeting

Sergo Beruashvili sergo_bero at icloud.com
Mon Mar 27 16:31:30 CDT 2017


That way you are just passing an argument to a closure, not capturing as I mentioned before, 

How would you create a closure for this function, that does something in background queue, then moves to main queue and changes a property of original struct? Can you provide a sample ?

Regards,
Sergo

> On 27 მარ. 2017, at 23:16, Michael Chiu <hatsuneyuji at icloud.com> wrote:
> 
> I tried the following code and it build and run. 
> 
> struct EmptyStruct {}
> func test(closure: @escaping (inout EmptyStruct) -> () ) {
>  var foo = EmptyStruct()
>  closure(&foo)
> }
> 
> Michael
>> On Mar 27, 2017, at 2:08 PM, 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.
>> 
>> 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.
>> Swift closures can't capture inout structs.
>> 
>> Regards,
>> Sergo
> 


More information about the swift-server-dev mailing list