This is the only part of the proposal that i can't concur!<br><br>^async^ at call side solve this nicely! And Pierre also showed how common people are doing it wrong! And will make this wrong using Futures too.<br><br>func doit() async {<br>        let dataResource = async loadWebResource("dataprofile.txt”)<br>        let imageResource = async loadWebResource("imagedata.dat”)<br>        let imageTmp = await decodeImage(dataResource, imageResource)<br> self.imageResult = await dewarpAndCleanupImage(imageTmp)<br>}<br><br>Anyway, we have time to think about it.<br><br><br><div class="gmail_quote"><div dir="ltr">Em sáb, 9 de set de 2017 às 20:30, David Hart via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> 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><blockquote type="cite"><div>On 10 Sep 2017, at 00:40, Kenny Leung via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br class="m_7630931665265230838Apple-interchange-newline"><div><div style="word-wrap:break-word"><div>Then isn’t the example functionally equivalent to:</div><div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"> <span style="color:#ba2da2">func</span> doit() {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"> <span style="color:#703daa">DispatchQueue</span>.<span style="color:#3e1e81">global</span>().<span style="color:#3e1e81">async</span> {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"> <span style="color:#ba2da2">let</span> dataResource = <span style="text-decoration:underline">loadWebResource</span>(<span style="color:#d12f1b">"dataprofile.txt"</span>)</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"> <span style="color:#ba2da2">let</span> imageResource = <span style="text-decoration:underline">loadWebResource</span>(<span style="color:#d12f1b">"imagedata.dat"</span>)</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"> <span style="color:#ba2da2">let</span> imageTmp = <span style="text-decoration:underline">decodeImage</span>(dataResource, imageResource)</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"> <span style="color:#ba2da2">let</span> imageResult = <span style="text-decoration:underline">dewarpAndCleanupImage</span>(imageTmp)</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(112,61,170);background-color:rgb(255,255,255)"><span> </span>DispatchQueue<span>.</span>main<span>.</span><span style="color:#3e1e81">async</span><span> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"> <span style="color:#ba2da2">self</span>.imageResult = imageResult</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"> }</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"> }</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"> }</div></div><div><br></div><div>if all of the API were synchronous? Why wouldn’t we just exhort people to write synchronous API code and continue using libdispatch? What am I missing?</div></div></div></blockquote><div><br></div></div></div><div style="word-wrap:break-word"><div><div>There are probably very good optimisations for going asynchronous, but I’m not the right person for that part of the answer.</div><div><br></div><div>But I can give another answer: once we have an async/await pattern, we can build Futures/Promises on top of them and then we can await on multiple asynchronous calls in parallel. But it won’t be a feature of async/await in itself:</div><div><br></div><div>func doit() async {<br><span class="m_7630931665265230838Apple-tab-span" style="white-space:pre-wrap">        </span>let dataResource = Future({ loadWebResource("dataprofile.txt”) })<br><span class="m_7630931665265230838Apple-tab-span" style="white-space:pre-wrap">        </span>let imageResource = Future({ loadWebResource("imagedata.dat”) })</div><div><span class="m_7630931665265230838Apple-tab-span" style="white-space:pre-wrap">        </span>let imageTmp = await decodeImage(dataResource.get, imageResource.get)<br> self.imageResult = await dewarpAndCleanupImage(imageTmp)<br>}</div></div></div><div style="word-wrap:break-word"><div><br><blockquote type="cite"><div><div style="word-wrap:break-word"><div>-Kenny</div><div><br></div><br><div><blockquote type="cite"><div>On Sep 8, 2017, at 2:33 PM, David Hart <<a href="mailto:david@hartbit.com" target="_blank">david@hartbit.com</a>> wrote:</div><br class="m_7630931665265230838Apple-interchange-newline"><div><div style="word-wrap:break-word"><br><div><blockquote type="cite"><div>On 8 Sep 2017, at 20:34, Kenny Leung via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br class="m_7630931665265230838Apple-interchange-newline"><div><div style="word-wrap:break-word">Hi All.<div><br></div><div>A point of clarification in this example:</div><div><br></div><div><pre style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,'Liberation Mono',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-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal;color:rgb(36,41,46);font-variant-ligatures:normal"><span class="m_7630931665265230838pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">func</span> <span class="m_7630931665265230838pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">loadWebResource</span>(<span class="m_7630931665265230838pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">_</span> <span class="m_7630931665265230838pl-smi" style="box-sizing:border-box">path</span>: <span class="m_7630931665265230838pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">String</span>) async <span class="m_7630931665265230838pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">-></span> Resource
<span class="m_7630931665265230838pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">func</span> <span class="m_7630931665265230838pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">decodeImage</span>(<span class="m_7630931665265230838pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">_</span> <span class="m_7630931665265230838pl-smi" style="box-sizing:border-box">r1</span>: Resource, <span class="m_7630931665265230838pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">_</span> <span class="m_7630931665265230838pl-smi" style="box-sizing:border-box">r2</span>: Resource) async <span class="m_7630931665265230838pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">-></span> Image
<span class="m_7630931665265230838pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">func</span> <span class="m_7630931665265230838pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">dewarpAndCleanupImage</span>(<span class="m_7630931665265230838pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">_</span> <span class="m_7630931665265230838pl-smi" style="box-sizing:border-box">i</span> : Image) async <span class="m_7630931665265230838pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">-></span> Image
<span class="m_7630931665265230838pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">func</span> <span class="m_7630931665265230838pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">processImageData1</span>() async <span class="m_7630931665265230838pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">-></span> Image {
<span class="m_7630931665265230838pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">let</span> dataResource <span class="m_7630931665265230838pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">=</span> await <span class="m_7630931665265230838pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">loadWebResource</span>(<span class="m_7630931665265230838pl-s" style="box-sizing:border-box;color:rgb(3,47,98)"><span class="m_7630931665265230838pl-pds" style="box-sizing:border-box">"</span>dataprofile.txt<span class="m_7630931665265230838pl-pds" style="box-sizing:border-box">"</span></span>)
<span class="m_7630931665265230838pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">let</span> imageResource <span class="m_7630931665265230838pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">=</span> await <span class="m_7630931665265230838pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">loadWebResource</span>(<span class="m_7630931665265230838pl-s" style="box-sizing:border-box;color:rgb(3,47,98)"><span class="m_7630931665265230838pl-pds" style="box-sizing:border-box">"</span>imagedata.dat<span class="m_7630931665265230838pl-pds" style="box-sizing:border-box">"</span></span>)
<span class="m_7630931665265230838pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">let</span> imageTmp <span class="m_7630931665265230838pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">=</span> await <span class="m_7630931665265230838pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">decodeImage</span>(dataResource, imageResource)
<span class="m_7630931665265230838pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">let</span> imageResult <span class="m_7630931665265230838pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">=</span> await <span class="m_7630931665265230838pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">dewarpAndCleanupImage</span>(imageTmp)
<span class="m_7630931665265230838pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">return</span> imageResult
}</pre><div><br></div></div><div>Do these:</div><div><br></div><div><pre style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,'Liberation Mono',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-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal;color:rgb(36,41,46);font-variant-ligatures:normal">await <span class="m_7630931665265230838pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">loadWebResource</span>(<span class="m_7630931665265230838pl-s" style="box-sizing:border-box;color:rgb(3,47,98)"><span class="m_7630931665265230838pl-pds" style="box-sizing:border-box">"</span>dataprofile.txt<span class="m_7630931665265230838pl-pds" style="box-sizing:border-box">"</span></span>)</pre><div><pre style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,'Liberation Mono',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-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal;color:rgb(36,41,46);font-variant-ligatures:normal">await <span class="m_7630931665265230838pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">loadWebResource</span>(<span class="m_7630931665265230838pl-s" style="box-sizing:border-box;color:rgb(3,47,98)"><span class="m_7630931665265230838pl-pds" style="box-sizing:border-box">"</span>imagedata.dat<span class="m_7630931665265230838pl-pds" style="box-sizing:border-box">"</span></span>)</pre><div><br></div></div></div><div>happen in in parallel?</div></div></div></blockquote><div><br></div><div>They don’t happen in parallel.</div><br><blockquote type="cite"><div><div style="word-wrap:break-word"><div>If so, how can I make the second one wait on the first one? If not, how can I make them go in parallel?</div><div><br></div><div>Thanks!</div><div><br></div><div>-Kenny</div><div><br></div></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></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" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></blockquote></div></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>