Good article. Thanks.<br><div class="gmail_quote"><div dir="ltr">Em sex, 22 de set de 2017 às 14:24, Kenny Leung via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; escreveu:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>Here’s more stuff I found on how this could work. It’s slowly becoming less murky to me.</div><div><br></div><div><a href="http://blog.stephencleary.com/2013/11/there-is-no-thread.html" target="_blank">http://blog.stephencleary.com/2013/11/there-is-no-thread.html</a></div></div><div style="word-wrap:break-word"><div><br></div><div>-Kenny</div></div><div style="word-wrap:break-word"><div><br></div><br><div><blockquote type="cite"><div>On Sep 20, 2017, at 7:19 AM, Adam Kemp via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br class="m_7818088380605804188Apple-interchange-newline"><div><div dir="auto">async/await doesn’t automatically make things run on another queue/thread. The code you wrote would execute synchronously on the original thread. <br><br><div>--<div>Adam Kemp</div></div><div><br>On Sep 19, 2017, at 11:36 PM, Trevör Anne Denise via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><div><blockquote type="cite"><div><br>Le 18 sept. 2017 à 18:07, Pierre Habouzit &lt;<a href="mailto:pierre@habouzit.net" target="_blank">pierre@habouzit.net</a>&gt; a écrit :</div><br class="m_7818088380605804188Apple-interchange-newline"><div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br class="m_7818088380605804188Apple-interchange-newline">-Pierre</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br><blockquote type="cite"><div>On Sep 18, 2017, at 2:04 AM, Trevör Anne Denise &lt;<a href="mailto:trevor.annedenise@icloud.com" target="_blank">trevor.annedenise@icloud.com</a>&gt; wrote:</div><br class="m_7818088380605804188Apple-interchange-newline"><div><blockquote type="cite" style="font-family:SFMono-Light;font-size:11px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div><br class="m_7818088380605804188Apple-interchange-newline">Le 18 sept. 2017 à 07:57, Pierre Habouzit &lt;<a href="mailto:pierre@habouzit.net" target="_blank">pierre@habouzit.net</a>&gt; a écrit :</div><br class="m_7818088380605804188Apple-interchange-newline"><div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><blockquote type="cite"><div>On Sep 17, 2017, at 3:52 AM, Trevör ANNE DENISE via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br class="m_7818088380605804188Apple-interchange-newline"><div><div>Hello everyone,<br><br>I have a few questions about async await in Swift.<br><br>Say that you have :<br><br>func foo() async {<br><span class="m_7818088380605804188Apple-tab-span" style="white-space:pre-wrap">        </span>print(&quot;Hey&quot;)<br><span class="m_7818088380605804188Apple-tab-span" style="white-space:pre-wrap">        </span>await bar()<br><span class="m_7818088380605804188Apple-tab-span" style="white-space:pre-wrap">        </span>print(&quot;How are you ?&quot;)<br>}<br><br>First of all, am I right to say that :<br>1) If the bar function wasn&#39;t an async function, the thread would be blocked until bar returns, at this point print(&quot;How are you ?&quot;) would be executed and its only after that that the function calling foo() would get back &quot;control&quot;<br></div></div></blockquote><div><br></div><div>I don&#39;t think you can quite call await without marking foo() as async (?).</div></div></div></blockquote><div style="font-family:SFMono-Light;font-size:11px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:SFMono-Light;font-size:11px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:SFMono-Light;font-size:11px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">Yes, that&#39;s what I meant, case one would call foo() without await if it wasn&#39;t async.</div><div style="font-family:SFMono-Light;font-size:11px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><br style="font-family:SFMono-Light;font-size:11px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><blockquote type="cite" style="font-family:SFMono-Light;font-size:11px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br><blockquote type="cite"><div><div>2) Here (with async bar function), if bar() takes some time to execute,</div></div></blockquote><div><br></div><div>Not quite, `await bar()` is afaict syntactic sugar for:</div><div><br></div></div><blockquote style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;margin:0px 0px 0px 40px;border:none;padding:0px"><div><div>bar {</div></div><div><div>    printf(&quot;How are you ?&quot;);</div></div><div><div>}</div></div></blockquote><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">Where bar used to take a closure before, the compiler is just making it for you. bar itself will be marked async and will handle its asynchronous nature e.g. using dispatch or something else entirely.</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">This has nothing to do with &quot;time&quot;.</div></div></blockquote><div style="font-family:SFMono-Light;font-size:11px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:SFMono-Light;font-size:11px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:SFMono-Light;font-size:11px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">If it&#39;s just syntactic sugar then how does this solve this issue mentioned in the concurrency manifesto ?</div><div style="font-family:SFMono-Light;font-size:11px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">&quot;Beyond being syntactically inconvenient, completion handlers are problematic because their syntax suggests that they will be called on the current queue, but that is not always the case. For example, one of the top recommendations on Stack Overflow is to implement your own custom async operations with code like this (Objective-C syntax):&quot;</div></div></blockquote><div><br></div><div>&quot;where&quot; things run is not addressed by async/await afaict, but Actors or any library-level usage of it.</div><br></div></div></blockquote><br></div><div><br></div><div>So since async await don&#39;t have any impact on where things are executed, what would happen concretely with this code ?</div><div><br></div><div>func slowFunction(_ input: [Int]) async -&gt; [Int] {</div><div><span class="m_7818088380605804188Apple-tab-span" style="white-space:pre-wrap">        </span>var results = [Int]()</div><div><span class="m_7818088380605804188Apple-tab-span" style="white-space:pre-wrap">        </span>for element in input {</div><div><span class="m_7818088380605804188Apple-tab-span" style="white-space:pre-wrap">                </span>results += [someLongComputation(with: element)]</div><div><span class="m_7818088380605804188Apple-tab-span" style="white-space:pre-wrap">        </span>}</div><div><span class="m_7818088380605804188Apple-tab-span" style="white-space:pre-wrap">        </span>return results</div><div>}</div><div><br></div><div>beginAsync {</div><div><span class="m_7818088380605804188Apple-tab-span" style="white-space:pre-wrap">        </span>await slowFunction(manyElements)</div><div>}</div><div><br></div><div>I didn&#39;t specified anything about which queue/thread runs this code, so what would happen ? Would beginAsync block until slowFunction completes ?</div><div><br></div><div><br></div><div>Trevör</div><div><br></div><br></div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></div>_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></blockquote></div><br></div>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div>