<div dir="ltr"><div>Thanks Pierre,</div><div><br></div><div>When I answered, I was using my smartphone, so I copied the first code snippet from stackoverflow I found and remove some words. And in that case I'm happy to be a flawed example, and yet, its was most voted on stackoverflow. (the full exemple also does other mistakes).</div><div><br></div><div>As Jonathan said, this only proves that it is important to have some basic primitive for parallelism. To avoid common mistakes. We dont need nothing complex rigth now! As Chris sayed, we are only making the ground layer.... But need to be a good and userfull layer to avoid rework in the future.</div><div><br></div><div>(Also, i see the wwdc talk. Good one, god job)</div><div dir="ltr"><br><div class="gmail_quote"><div dir="ltr">Em seg, 4 de set de 2017 às 17:48, Pierre Habouzit <<a href="mailto:phabouzit@apple.com" target="_blank">phabouzit@apple.com</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;line-break:after-white-space">This doesn't work for priority tracking purposes, and is bad for locking domains too.<div><br></div><div>What you really want here is:</div><div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div>let groupLike : Dispatch.SomethingThatLooksLikeAGroupButDoesTracking()</div><div><br></div><div>myNetworkingQueue().async(group: groupLike) {</div><div> // loadWebResource</div><div>}</div><div><div>myNetworkingQueue().async(group: groupLike) {</div></div><div><div> // loadWebResource</div></div><div><div>}</div></div><div>groupLike.notify(myImageProcessingQueue()) {</div><div> // decodeImage</div><div>}</div></blockquote><div><br></div><div>The two main differences with what you explained is:</div><div><br></div><div>1) `groupLike` would definitely be the underlying thing that tracks dependencies which is required for a higher level Future-like construct (which async/await doesn't have to solve, provided that it captures enough context for the sake of such a groupLike object).</div><div><br></div><div>`groupLike` would likely *NOT* be an object developers would manipulate directly but rather the underlying mechanism.</div><div><br></div><div>2) the loadWebResource is done from the same serial context, because networking is already (if your library is sane) using an asynchronous interface that is very rarely a CPU bound problem, so parallelizing it is not worth it because synchronization cost will dominate. To give hindsight, our WWDC talk at the beginning pitched this measured performance win in a real life scenario:</div><div><br></div><div>
                
        
        
                <div class="m_5793201312926003956m_-5456485526747519412page" title="Page 6">
                        <div class="m_5793201312926003956m_-5456485526747519412section">
                                <div class="m_5793201312926003956m_-5456485526747519412layoutArea">
                                        <div class="m_5793201312926003956m_-5456485526747519412column"><p style="text-align:center"><span style="font-weight:700;font-size:144px"><font face="HelveticaNeue">1.3x
</font></span></p><p style="text-align:center"><font face="HelveticaNeue" size="5">faster after combining queue hierarchies</font></p>
                                        </div>
                                </div>
                        </div>
                </div></div><div><br></div><div>This is covered here:</div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><a href="https://developer.apple.com/videos/play/wwdc2017/706/?time=138" target="_blank">https://developer.apple.com/videos/play/wwdc2017/706/?time=138</a></div><div><a href="https://developer.apple.com/videos/play/wwdc2017/706/?time=1500" target="_blank">https://developer.apple.com/videos/play/wwdc2017/706/?time=1500</a> and onward</div></blockquote><div><br></div><div>It happens that this 30%+ performance win that we discuss here happens to have actually be with how some subsystems were using our networking stack, by recombining code that was essentially doing what you wrote into what I just wrote above by using the same exclusion context for all networking.</div><div><br></div><div>If Swift async/await leads to people writing things equivalent to using the global queue the way you suggest, we failed from a system performance perspective.</div><div></div></div><div style="word-wrap:break-word;line-break:after-white-space"><div><br><div>
-Pierre
</div>
</div></div><div style="word-wrap:break-word;line-break:after-white-space"><div><div><blockquote type="cite"><div>On Sep 4, 2017, at 12:55 PM, Wallacy via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br class="m_5793201312926003956m_-5456485526747519412Apple-interchange-newline"></blockquote></div></div></div><div style="word-wrap:break-word;line-break:after-white-space"><div><div><blockquote type="cite"><div><div dir="ltr">Yes, maybe in this way... Or using dispatch_group..<div><br></div><div><pre class="m_5793201312926003956m_-5456485526747519412inbox-inbox-lang-c m_5793201312926003956m_-5456485526747519412inbox-inbox-prettyprinted m_5793201312926003956m_-5456485526747519412inbox-inbox-prettyprint" style="margin-top:0px;margin-bottom:1em;padding:5px;border:0px;font-variant-numeric:inherit;font-stretch:inherit;line-height:inherit;font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace,sans-serif;vertical-align:baseline;width:auto;max-height:600px;overflow:auto;background-color:rgb(239,240,241);color:rgb(57,51,24);word-wrap:normal"><code style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace,sans-serif;vertical-align:baseline;white-space:inherit"><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-typ" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(43,145,175)">dispatch_group_t</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pln" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)"> group </span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pun" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">=</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pln" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)"> dispatch_group_create</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pun" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">();</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pln" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">
dispatch_group_async</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pun" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">(</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pln" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">group</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pun" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">,</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pln" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">dispatch_get_global_queue</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pun" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">(</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pln" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">0</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pun" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">,</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pln" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)"> </span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-lit" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(125,39,39)">0</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pun" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">),</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pln" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)"> </span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pun" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">^</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pln" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)"> </span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pun" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">{</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pln" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">
</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-com" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(133,140,147)">// loadWebResource</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pln" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">
</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pun" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">});</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pln" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">
dispatch_group_async</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pun" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">(</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pln" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">group</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pun" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">,</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pln" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">dispatch_get_global_queue</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pun" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">(</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pln" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">0</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pun" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">,</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pln" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)"> </span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-lit" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(125,39,39)">0</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pun" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">),</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pln" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)"> </span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pun" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">^</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pln" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)"> </span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pun" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">{</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pln" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">
</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-com" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(133,140,147)">// loadWebResource</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pln" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">
</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pun" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">});</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pln" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">
dispatch_group_notify</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pun" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">(</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pln" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">group</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pun" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">,</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pln" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">dispatch_get_global_queue</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pun" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">(</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pln" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">0</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pun" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">,</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pln" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)"> </span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-lit" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(125,39,39)">0</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pun" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">),</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pln" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)"> </span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pun" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">^</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pln" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)"> </span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pun" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">{</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pln" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">
</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-com" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(133,140,147)">// decodeImage ... etc...</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pln" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">
</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pun" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">});</span><span class="m_5793201312926003956m_-5456485526747519412inbox-inbox-pln" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">
</span><br></code></pre>Can be made using different strategies, the compiler will select the best fit for every case. Different runtimes, has different "best" strategies also. No need to use a intermediary type.<br></div></div><br><div class="gmail_quote"><div dir="ltr">Em seg, 4 de set de 2017 às 14:53, Michel Fortin <<a href="mailto:michel.fortin@michelf.ca" target="_blank">michel.fortin@michelf.ca</a>> escreveu:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
> Le 4 sept. 2017 à 10:01, Wallacy via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> a écrit :<br>
><br>
> func processImageData1a() async -><br>
> Image {<br>
> let dataResource = async loadWebResource("dataprofile.txt")<br>
> let imageResource = async loadWebResource("imagedata.dat")<br>
><br>
> // ... other stuff can go here to cover load latency...<br>
><br>
> let imageTmp = await decodeImage(dataResource, imageResource) // compiler error if await is not present.<br>
> let imageResult = await dewarpAndCleanupImage(imageTmp)<br>
> return imageResult<br>
> }<br>
><br>
><br>
> If this (or something like that) is not implemented, people will create several versions to solve the same problem, so that later (Swift 6?) will be solved (because people want this), and we will live with several bad codes to maintain.<br>
<br>
Just to be sure of what you are proposing, am I right to assume this would be compiled down to something like this?<br>
<br>
func processImageData1a(completion: (Image) -> ()) {<br>
var dataResource: Resource? = nil<br>
var imageResource: Resource? = nil<br>
var finishedBody = false<br>
<br>
func continuation() {<br>
// only continue once everything is ready<br>
guard finishedBody else { return }<br>
guard dataResource = dataResource else { return }<br>
guard imageResource = imageResource else { return }<br>
<br>
// everything is ready now<br>
decodeImage(dataResource, imageResource) { imageTmp in<br>
dewarpAndCleanupImage(imageTmp) { imageResult in<br>
completion(imageResult)<br>
}<br>
}<br>
}<br>
<br>
loadWebResource("dataprofile.txt") { result in<br>
dataResource = result<br>
continuation()<br>
}<br>
loadWebResource("imagedata.dat") { result in<br>
imageResource = result<br>
continuation()<br>
}<br>
<br>
// ... other stuff can go here to cover load latency...<br>
<br>
finishedBody = true<br>
continuation()<br>
}<br>
<br>
<br>
This seems more lightweight than a future to me. I know I've used this pattern a few times. What I'm not sure about is how thrown errors would work. Surely you want error handling to work when loading resources from the web.<br>
<br>
<br>
--<br>
Michel Fortin<br>
<a href="https://michelf.ca/" rel="noreferrer" target="_blank">https://michelf.ca</a><br>
<br>
</blockquote></div></div></blockquote></div></div></div><div style="word-wrap:break-word;line-break:after-white-space"><div><div><blockquote type="cite"><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></div></blockquote></div></div></div>