<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Nov 9, 2017, at 11:02 AM, Wallacy &lt;<a href="mailto:wallacyf@gmail.com" class="">wallacyf@gmail.com</a>&gt; wrote:</div><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class="">So for me, this:</div><div class=""><br class=""></div><div class=""><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px;color:rgb(33,33,33);font-size:13px" class=""><div class="">func OnButtonClicked(_ sender:AnyObject) {</div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px;color:rgb(33,33,33);font-size:13px" class=""><div class="">&nbsp; &nbsp; let button = sender as! UIButton</div><div class="">&nbsp; &nbsp; button.isEnabled = false</div><div class="">&nbsp; &nbsp; beginAsync {</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; await DoSomethingAsync()</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; button.isEnabled = true</div><div class="">&nbsp; &nbsp; }</div><div class="">}</div></blockquote></div><div class=""><br class=""></div><div class="">Does not make any sense... Because await will not block the thread we can assume (like the exemple on proposal) that compiler will actually do the same what we will do using GDC and pick everyone to until the context ends and encapsulate as completion handle to the away call.</div></div></div></blockquote><div><br class=""></div><div>I don’t understand what you’re saying here. In terms of GCD the above code is basically equivalent to this:</div><div><br class=""></div></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div><div>func buttonClicked(_ sender:AnyObject) {</div><div>&nbsp; &nbsp; let button = sender as! UIButton</div><div>&nbsp; &nbsp; button.isEnabled = false</div><div>&nbsp; &nbsp; doSomethingAsync { // completion callback, assume it’s on the main queue</div><div>&nbsp; &nbsp; &nbsp; &nbsp; button.isEnabled = true</div><div>&nbsp; &nbsp; }</div><div>}</div></div></blockquote><div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="">And this one:</div><div class=""><br class=""></div><div class=""><pre style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,&quot;Liberation Mono&quot;,Menlo,Courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;word-wrap:normal;padding:16px;overflow:auto;line-height:1.45;background-color:rgb(246,248,250);border-radius:3px;word-break:normal;color:rgb(36,41,46)" class=""><span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">@IBAction</span> <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">func</span> <span class="inbox-inbox-pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">buttonDidClick</span>(<span class="inbox-inbox-pl-smi" style="box-sizing:border-box"><span class="inbox-inbox-pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">sender</span></span>:<span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">AnyObject</span>) {
  beginAsync {
    <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">let</span> image <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">=</span> await <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">processImageData</span>()
    <span class="inbox-inbox-pl-c" style="box-sizing:border-box;color:rgb(106,115,125)"><span class="inbox-inbox-pl-c" style="box-sizing:border-box">//</span> Do the update on the main thread/queue since it owns imageView.</span>
<span class="inbox-inbox-pl-c" style="box-sizing:border-box;color:rgb(106,115,125)"></span>    mainQ.<span class="inbox-inbox-pl-smi" style="box-sizing:border-box">async</span> {
      imageView.<span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">image</span> <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">=</span> image
    }
  }
}</pre></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Does not make any sense too.</div><div class=""><br class=""></div><div class="">The only way to&nbsp;<span style="background-color:rgb(246,248,250);color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,&quot;Liberation Mono&quot;,Menlo,Courier,monospace;font-size:13.6px" class="">await</span>  to do not block the thread is make a early return like beginAsync and encapsulate as completion handle the rest of the code.&nbsp;</div></div></div></blockquote><div><br class=""></div><div>This is why “await” can only be used in a function that is marked as “async”. The “async” keyword tells the compiler that this function will be broken up into parts, and its return value will be produced asynchronously.</div><div><br class=""></div><div>One thing that might be confusing is that in the examples using “beginAsync” the trailing closure is the async function. That’s not obvious because there’s no “async” keyword, but it’s there in the signature of the closure argument:</div><div><br class=""></div></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div><div>func&nbsp;beginAsync(_&nbsp;body: () async&nbsp;throws&nbsp;-&gt;&nbsp;Void)&nbsp;rethrows&nbsp;-&gt;&nbsp;Void</div></div></blockquote><div class=""><br class=""></div>I’m not sure how the proposed design handles type checking for async closures. Is async part of the type? Can I declare a local closure variable as async? What are the rules for conversion between async and non-async closures? Is it a warning or error to use a closure literal without an async keyword that is assigned to an async closure variable or passed as an async closure argument?<div class=""><br class=""></div><div class="">C# dodges all of these issues because async isn't part of the type system. Closures that don’t return anything can be declared async just like void functions, and code that uses void-returning closures doesn’t need to care whether the implementation is async or not.<div><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""></div></div>
</div></blockquote></div><br class=""></div></body></html>