<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<div name="messageReplySection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;"><br />
On 25 août 2017 18:31 -0400, Jonathan Hull <jhull@gbis.com>, wrote:<br />
<blockquote type="cite" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #1abc9c;">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>
</blockquote>
<div>why would it? the async modifier could very well be used to transform a sync function into an async one, dispatching on a defined queue returning the 'Future' and resolving once the function completes.</div>
<div><br /></div>
<div>I'm not sure why it's understood as all or nothing, AFAICU, await is just a way to block the current queue and wait for a result from an async function.</div>
<div>beginAsync is a way to make sure we don't block the current execution queue.</div>
<div><br /></div>
<div>something like</div>
<div><br /></div>
<div>let a = await async longSynchrounousCall() would block the current execution queue (because await) but the execution of the longSynchronousCall() would be on a separate queue / block.</div>
<div><br /></div>
<div>The question lays more in where the calls are executed, either they are dispatched after, current block is suspended, runloop continues, and then the block is re-entered upon returning.  that would lead to some weird executions flows.</div>
<div><br /></div>
<blockquote type="cite" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #1abc9c;">
<div class="">
<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="" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #e67e22;">
<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="">
<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 #3498db;" 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 #d35400;">
<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 #34495e;" 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>
</blockquote>
<div></div>
</div>
</body>
</html>