<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">But then it would need to be called with await under the current proposal, meaning that either:<div class=""><br class=""><div class="">• b would await the calculation of a</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>beginAsync {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span>let a = await longCalculationA()</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span>let b = await longCalculationB() //This only calculates when a is finished</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div class=""><br class=""></div><div class="">• or b would be executed while a is awaiting, but a and b would be in different scopes</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>beginAsync{</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span>let a = await longCalculationA()</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>beginAsync{</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span>let b = await longCalculationB() //We can’t see ‘a’ anymore</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>//We can’t see ‘a’ or ‘b’ here to use them</div><div class=""><br class=""></div><div class="">We could, also implement some sort of future, and then <i class="">re-write</i> our functions to take advantage of it, but this misses out on numerous compiler optimizations and requires our functions to be written with futures in mind. In my example, the functions can just be written as async, and they don’t care whether they are called with async or await.</div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">Jon</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Aug 25, 2017, at 3:13 PM, Florent Vilmart <<a href="mailto:florent@flovilmart.com" class="">florent@flovilmart.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">
<title class=""></title>
<div class="">
<div name="messageBodySection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;" class="">be doesn't wait if it's defined as
<div class=""><br class=""></div>
<div class="">func <span style="color: rgb(51, 51, 51); font-family: 'Helvetica Neue';" class="">longCalculationB() async -> SomeType </span></div>
<div class=""><span style="color: rgb(51, 51, 51); font-family: 'Helvetica Neue';" class=""><br class=""></span></div>
<div class=""><span style="color: rgb(51, 51, 51); font-family: 'Helvetica Neue';" class="">which would be helpful if it's a long calculation, </span></div>
<div class=""><span style="color: rgb(51, 51, 51); font-family: 'Helvetica Neue';" class=""><br class=""></span></div>
<div class=""><span style="color: rgb(51, 51, 51); font-family: 'Helvetica Neue';" class="">in the case it's</span></div>
<div class=""><span style="color: rgb(51, 51, 51); font-family: 'Helvetica Neue';" class=""><br class=""></span></div>
<div class="">func <span style="color: rgb(51, 51, 51); font-family: 'Helvetica Neue';" class="">longCalculationB() -> SomeType </span><span style="color: rgb(51, 51, 51); font-family: 'Helvetica Neue';" class=""><br class=""></span></div>
<div class=""><span style="color: rgb(51, 51, 51); font-family: 'Helvetica Neue';" class=""><br class=""></span></div>
<div class=""><font color="#333333" face="Helvetica Neue" class="">That would probably be valid to put the async keyword front even though I would not be a big fan of that as you'd be executing on an indefinite queue a calculation that may not be thread safe.</font></div>
<div class=""><font color="#333333" face="Helvetica Neue" class=""><br class=""></font></div>
<div class=""><font color="#333333" face="Helvetica Neue" class="">async would be in that case a wrapper around dispatch_async + semaphore</font></div>
<div class=""><br class=""></div>
</div>
<div name="messageReplySection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;" class=""><br class="">
On 25 août 2017 18:08 -0400, Jonathan Hull <<a href="mailto:jhull@gbis.com" class="">jhull@gbis.com</a>>, wrote:<br class="">
<blockquote type="cite" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #1abc9c;" class="">Why wouldn’t b wait for a in this example? If it is using futures, those aren’t available in the current proposal.
<div class=""><br class="">
<div class="">
<blockquote type="cite" class="" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #e67e22;">
<div class="">On Aug 25, 2017, at 3:02 PM, Florent Vilmart <<a href="mailto:florent@flovilmart.com" class="">florent@flovilmart.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div class="">
<div name="messageBodySection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;" class="">Probably with:
<div class=""><br class=""></div>
<div class="">
<div style="margin: 0px; line-height: normal; font-family: 'Helvetica Neue'; color: rgb(51, 51, 51);" class="">let a = longCalculationA() </div>
<div style="margin: 0px; line-height: normal; font-family: 'Helvetica Neue'; color: rgb(51, 51, 51);" class="">let b = longCalculationB() //b doesn’t wait for a to complete before starting</div>
<div style="margin: 0px; line-height: normal; font-family: 'Helvetica Neue'; color: rgb(51, 51, 51);" class="">let c = longCalculationC() //c doesn’t wait for a or b</div>
<div style="margin: 0px; line-height: normal; font-family: 'Helvetica Neue'; color: rgb(51, 51, 51);" class="">let (aResult, bResult, cResult) = await Future.collect(a, b, c) //waits until a, b, and c are all available</div>
</div>
</div>
<div name="messageReplySection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;" class=""><br class="">
On 25 août 2017 17:48 -0400, wrote:<br class="">
<blockquote type="cite" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #3498db;" class=""><br class="">
<div class="">let a = async longCalculationA()<br class="">
let b = async longCalculationB() //b doesn’t wait for a to complete before starting<br class="">
let c = async longCalculationC() //c doesn’t wait for a or b<br class="">
let result = await combineCalculations(a: a, b: b, c: c) //waits until a, b, and c are all available</div>
</blockquote>
<div class=""></div>
</div>
</div>
</div>
</blockquote>
</div>
<br class=""></div>
</blockquote>
<div class=""></div>
</div>
</div>
</div></blockquote></div><br class=""></div></div></body></html>