<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="">This doesn't work for priority tracking purposes, and is bad for locking domains too.<div class=""><br class=""></div><div class="">What you really want here is:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class="">let groupLike : Dispatch.SomethingThatLooksLikeAGroupButDoesTracking()</div><div class=""><br class=""></div><div class="">myNetworkingQueue().async(group: groupLike) {</div><div class="">&nbsp; &nbsp; // loadWebResource</div><div class="">}</div><div class=""><div class="">myNetworkingQueue().async(group: groupLike) {</div></div><div class=""><div class="">&nbsp; &nbsp; // loadWebResource</div></div><div class=""><div class="">}</div></div><div class="">groupLike.notify(myImageProcessingQueue()) {</div><div class="">&nbsp; &nbsp; // decodeImage</div><div class="">}</div></blockquote><div class=""><br class=""></div><div class="">The two main differences with what you explained is:</div><div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">`groupLike` would likely *NOT* be an object developers would manipulate directly but rather the underlying mechanism.</div><div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">
                
        
        
                <div class="page" title="Page 6">
                        <div class="section">
                                <div class="layoutArea">
                                        <div class="column"><p style="text-align: center;" class=""><span style="font-weight: 700; font-size: 144px;" class=""><font face="HelveticaNeue" class="">1.3x
</font></span></p><p style="text-align: center;" class=""><font face="HelveticaNeue" size="5" class="">faster after combining queue hierarchies</font></p>
                                        </div>
                                </div>
                        </div>
                </div></div><div class=""><br class=""></div><div class="">This is covered here:</div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><a href="https://developer.apple.com/videos/play/wwdc2017/706/?time=138" class="">https://developer.apple.com/videos/play/wwdc2017/706/?time=138</a></div><div class=""><a href="https://developer.apple.com/videos/play/wwdc2017/706/?time=1500" class="">https://developer.apple.com/videos/play/wwdc2017/706/?time=1500</a>&nbsp;and onward</div></blockquote><div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">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 class=""><br class=""><div class="">
-Pierre

</div>
<div><br class=""><blockquote type="cite" class=""><div class="">On Sep 4, 2017, at 12:55 PM, Wallacy via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Yes, maybe in this way... Or using dispatch_group..<div class=""><br class=""></div><div class=""><pre class="inbox-inbox-lang-c inbox-inbox-prettyprinted inbox-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,&quot;Lucida Console&quot;,&quot;Liberation Mono&quot;,&quot;DejaVu Sans Mono&quot;,&quot;Bitstream Vera Sans Mono&quot;,&quot;Courier New&quot;,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,&quot;Lucida Console&quot;,&quot;Liberation Mono&quot;,&quot;DejaVu Sans Mono&quot;,&quot;Bitstream Vera Sans Mono&quot;,&quot;Courier New&quot;,monospace,sans-serif;vertical-align:baseline;white-space:inherit" class=""><span class="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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="inbox-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 class=""></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 class=""></div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="">Em seg, 4 de set de 2017 às 14:53, Michel Fortin &lt;<a href="mailto:michel.fortin@michelf.ca" class="">michel.fortin@michelf.ca</a>&gt; escreveu:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br class="">
&gt; Le 4 sept. 2017 à 10:01, Wallacy via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; a écrit :<br class="">
&gt;<br class="">
&gt; func processImageData1a() async -&gt;<br class="">
&gt;&nbsp; Image {<br class="">
&gt;&nbsp; &nbsp;let dataResource&nbsp; = async loadWebResource("dataprofile.txt")<br class="">
&gt;&nbsp; &nbsp;let imageResource = async loadWebResource("imagedata.dat")<br class="">
&gt;<br class="">
&gt;&nbsp; &nbsp;// ... other stuff can go here to cover load latency...<br class="">
&gt;<br class="">
&gt;&nbsp; &nbsp;let imageTmp&nbsp; &nbsp; = await decodeImage(dataResource, imageResource) // compiler error if await is not present.<br class="">
&gt;&nbsp; &nbsp;let imageResult = await dewarpAndCleanupImage(imageTmp)<br class="">
&gt;&nbsp; &nbsp;return imageResult<br class="">
&gt; }<br class="">
&gt;<br class="">
&gt;<br class="">
&gt; 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 class="">
<br class="">
Just to be sure of what you are proposing, am I right to assume this would be compiled down to something like this?<br class="">
<br class="">
func processImageData1a(completion: (Image) -&gt; ()) {<br class="">
&nbsp; var dataResource: Resource? = nil<br class="">
&nbsp; var imageResource: Resource? = nil<br class="">
&nbsp; var finishedBody = false<br class="">
<br class="">
&nbsp; func continuation() {<br class="">
&nbsp; &nbsp; // only continue once everything is ready<br class="">
&nbsp; &nbsp; guard finishedBody else { return }<br class="">
&nbsp; &nbsp; guard dataResource = dataResource else { return }<br class="">
&nbsp; &nbsp; guard imageResource = imageResource else { return }<br class="">
<br class="">
&nbsp; &nbsp; // everything is ready now<br class="">
&nbsp; &nbsp; decodeImage(dataResource, imageResource) { imageTmp in<br class="">
&nbsp; &nbsp; &nbsp; dewarpAndCleanupImage(imageTmp) { imageResult in<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; completion(imageResult)<br class="">
&nbsp; &nbsp; &nbsp; }<br class="">
&nbsp; &nbsp; }<br class="">
&nbsp; }<br class="">
<br class="">
&nbsp; loadWebResource("dataprofile.txt") { result in<br class="">
&nbsp; &nbsp; dataResource = result<br class="">
&nbsp; &nbsp; continuation()<br class="">
&nbsp; }<br class="">
&nbsp; loadWebResource("imagedata.dat") { result in<br class="">
&nbsp; &nbsp; imageResource = result<br class="">
&nbsp; &nbsp; continuation()<br class="">
&nbsp; }<br class="">
<br class="">
&nbsp; // ... other stuff can go here to cover load latency...<br class="">
<br class="">
&nbsp; finishedBody = true<br class="">
&nbsp; continuation()<br class="">
}<br class="">
<br class="">
<br class="">
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 class="">
<br class="">
<br class="">
--<br class="">
Michel Fortin<br class="">
<a href="https://michelf.ca/" rel="noreferrer" target="_blank" class="">https://michelf.ca</a><br class="">
<br class="">
</blockquote></div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></body></html>