<div dir="ltr">Interesting, its syntax seems to improve the "fire and forget" issue.<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;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal;color:rgb(36,41,46)"><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)">buttonClicked</span>() {
        async <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">downloadAndUpdateImageView</span>()
}</pre><div><br></div>In this case, the return Future<void> also does not need to be produced as one of the compiler optimization.</div><div><br></div><div>Also,</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;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal;color:rgb(36,41,46)"><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)">someAsyncFunc</span>() async <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">-></span> User {
        <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">var</span> userData <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">=</span> async <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">downloadUserData</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> userData is of type Future<UserData> as we used async</span>
<span class="inbox-inbox-pl-c" style="box-sizing:border-box;color:rgb(106,115,125)"></span>        <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">var</span> image <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">=</span> async <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">downloadImage</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> Equivalentely, image is of type Future<UIImage></span>
<span class="inbox-inbox-pl-c" style="box-sizing:border-box;color:rgb(106,115,125)"></span>        <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">return</span> await <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">User</span>(userData, image) <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> Await is somehow "unwarping" the futures back into UserData and UIImage</span>
<span class="inbox-inbox-pl-c" style="box-sizing:border-box;color:rgb(106,115,125)"></span>}</pre><br></div><div>Makes sense to me, its pretty clear that <span style="color:rgb(0,92,197);background-color:rgb(246,248,250);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:13.6px">downloadUserData</span> and <span style="color:rgb(0,92,197);background-color:rgb(246,248,250);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:13.6px">downloadImage</span> can be run in parallel, and the "sync point" is the only point when you need the actual value.<br></div><div><br></div><div>What made me curious about this pattern is to do something like that:</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;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal;color:rgb(36,41,46)"><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)">getUser</span>() async <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">-></span> User {
        <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">var</span> userData <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">=</span> async <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">downloadUserData</span>()
<span class="inbox-inbox-pl-c" style="box-sizing:border-box;color:rgb(106,115,125)"></span>        <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">var</span> image <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">=</span> async <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">downloadImage</span>()
<span class="inbox-inbox-pl-c" style="box-sizing:border-box;color:rgb(106,115,125)"></span>        <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">return</span> async <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">User</span>(userData, image)
<span class="inbox-inbox-pl-c" style="box-sizing:border-box;color:rgb(106,115,125)"></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)">SomethingUsingUser</span>() <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">-></span> <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">Void</span> {
        <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">var</span> user <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)">getUser</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>Only here</span>
<span class="inbox-inbox-pl-c" style="box-sizing:border-box;color:rgb(106,115,125)"></span>        <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">printf</span>(user.<span class="inbox-inbox-pl-smi" style="box-sizing:border-box">age</span> <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">></span> <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">21</span> <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">?</span> <span class="inbox-inbox-pl-s" style="box-sizing:border-box;color:rgb(3,47,98)"><span class="inbox-inbox-pl-pds" style="box-sizing:border-box">"</span>Let's Drink<span class="inbox-inbox-pl-pds" style="box-sizing:border-box">"</span></span> <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">:</span> <span class="inbox-inbox-pl-s" style="box-sizing:border-box;color:rgb(3,47,98)"><span class="inbox-inbox-pl-pds" style="box-sizing:border-box">"</span>See you later!<span class="inbox-inbox-pl-pds" style="box-sizing:border-box">"</span></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> OR</span>
<span class="inbox-inbox-pl-c" style="box-sizing:border-box;color:rgb(106,115,125)"></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)">Something2UsingUser</span>() <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">-></span> <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">Void</span> {
        <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">var</span> user <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">=</span> async <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">getUser</span>()
        <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">var</span> ageToDrink <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">=</span> <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">getDrinkAge</span>();
<span class="inbox-inbox-pl-c" style="box-sizing:border-box;color:rgb(106,115,125)"></span>        <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">printf</span>(user.<span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">get</span>().<span class="inbox-inbox-pl-smi" style="box-sizing:border-box">age</span> <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">></span> ageToDrink <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">?</span> <span class="inbox-inbox-pl-s" style="box-sizing:border-box;color:rgb(3,47,98)"><span class="inbox-inbox-pl-pds" style="box-sizing:border-box">"</span>Let's Drink<span class="inbox-inbox-pl-pds" style="box-sizing:border-box">"</span></span> <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">:</span> <span class="inbox-inbox-pl-s" style="box-sizing:border-box;color:rgb(3,47,98)"><span class="inbox-inbox-pl-pds" style="box-sizing:border-box">"</span>See you later!<span class="inbox-inbox-pl-pds" style="box-sizing:border-box">"</span></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> OR</span>
<span class="inbox-inbox-pl-c" style="box-sizing:border-box;color:rgb(106,115,125)"></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)">Something2UsingUser</span>() <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">-></span> <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">Void</span> {
        <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">var</span> user <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">=</span> async <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">getUser</span>()
        <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">var</span> ageToDrink <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">=</span> async <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">getDrinkAge</span>();
        <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">printf</span>(await user.<span class="inbox-inbox-pl-smi" style="box-sizing:border-box">age</span> <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">></span> ageToDrink <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">?</span> <span class="inbox-inbox-pl-s" style="box-sizing:border-box;color:rgb(3,47,98)"><span class="inbox-inbox-pl-pds" style="box-sizing:border-box">"</span>Lets Drink<span class="inbox-inbox-pl-pds" style="box-sizing:border-box">"</span></span> <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">:</span> <span class="inbox-inbox-pl-s" style="box-sizing:border-box;color:rgb(3,47,98)"><span class="inbox-inbox-pl-pds" style="box-sizing:border-box">"</span>See you latter!<span class="inbox-inbox-pl-pds" style="box-sizing:border-box">"</span></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> i dont know if this make sense</span>
<span class="inbox-inbox-pl-c" style="box-sizing:border-box;color:rgb(106,115,125)"></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> OR maybe continue the process</span>
<span class="inbox-inbox-pl-c" style="box-sizing:border-box;color:rgb(106,115,125)"></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)">CanDrink</span>() <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">-></span> async bool {
        <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">var</span> user <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">=</span> async <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">getUser</span>()
        <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">return</span> <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">async</span> ()<span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">=></span>{ user.<span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">get</span>().<span class="inbox-inbox-pl-smi" style="box-sizing:border-box">age</span> <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">></span> <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">21</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> Or other way to pass a future computation.</span>
<span class="inbox-inbox-pl-c" style="box-sizing:border-box;color:rgb(106,115,125)"></span>}</pre></div><div>But the bast part is enable this:</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;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal;color:rgb(36,41,46)"><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)">CanDrink</span>() <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">-></span> bool {
        <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">var</span> user <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">=</span> async <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">getUser</span>()
        <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">var</span> isOpenToDrink <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">=</span> <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">barIsOpen</span>()
        <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">return</span> isOpenToDrink <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">?</span> (user.<span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">get</span>().<span class="inbox-inbox-pl-smi" style="box-sizing:border-box">age</span> <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">></span> <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">21</span>) <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">:</span> <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">false</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> if bar is not open, we dont need to evaluate user, and the task can be suspended somehow.</span>
<span class="inbox-inbox-pl-c" style="box-sizing:border-box;color:rgb(106,115,125)"></span>}</pre></div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">Em qui, 24 de ago de 2017 às 08:40, Trevör ANNE DENISE 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">Hello Swift community,<div><br></div><div>I was really interested by the recent<i> Task-based concurrency manifesto</i> and <i>Concrete proposal for async semantics in Swift.</i></div><div><i><br></i></div><div>Looking at beginAsync() and Futures, I had an idea for a new syntax based on the `async` keyword, I'd love to hear your feedback about this idea:</div><div><a href="https://github.com/adtrevor/Swift-ideas/blob/master/New%20async%20keyword%20usage.md" target="_blank">https://github.com/adtrevor/Swift-ideas/blob/master/New%20async%20keyword%20usage.md</a></div><div><br></div><div>Would such a syntax make any sense?</div><div><br></div><div>Thank you ! :)</div><div><br></div><div><br></div><div>Trevör</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>