<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On 24 Aug 2017, at 22:05, Thomas 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 style="font-family: Helvetica; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class=""><div class=""><br class="Apple-interchange-newline">On 24 Aug 2017, at 21:48, Marc Schlichte &lt;<a href="mailto:marc.schlichte@googlemail.com" class="">marc.schlichte@googlemail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br class=""><div class=""><blockquote type="cite" class=""><div class="">Am 24.08.2017 um 01:56 schrieb Adam Kemp &lt;<a href="mailto:adam.kemp@apple.com" class="">adam.kemp@apple.com</a>&gt;:</div><br class="Apple-interchange-newline"><div class=""><br class="Apple-interchange-newline"><br class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><blockquote type="cite" class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class="">On Aug 23, 2017, at 4:28 PM, Marc Schlichte 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 class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br class=""><div class=""><blockquote type="cite" class=""><div class="">Am 23.08.2017 um 12:29 schrieb Thomas via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt;:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 23 Aug 2017, at 11:28, Thomas 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=""><span class="" style="font-family: Helvetica; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;">1. What happens to the actor's queue when the body of a (non void-returning) actor method awaits away on some other actor? Does it suspend the queue to prevent other messages from being processes? It would seem to be the expected behavior but we'd also need a way to detach from the actor's queue in order to allow patterns like starting a long-running background operation and still allowing other messages to be processed (for example, calling a cancel() method). We could still do these long-running operations by passing a completion block to the method, rather than via its return value. That would clarify this goes beyond this one actor message, but we're back to the old syntax...</span></div></blockquote></div><br class=""><div class="">Maybe that's where Futures would come in handy? Just return a Future from the method so callers can await long-running operations.</div></div></div></blockquote><div class=""><br class=""></div><div class="">If you wrap the call to a long-running operation of another actor in a `beginAsync`, I would assume that other `actor funcs` of your actor will be able to run even while</div><div class="">&nbsp;the long-running operation is pending:</div><div class=""><br class=""></div><div class="">actor class Caller {</div><div class="">&nbsp; let callee = Callee()</div><div class="">&nbsp; var state = SomeState()</div><div class=""><br class=""></div><div class="">&nbsp; actor func foo() {</div><div class="">&nbsp; &nbsp; beginAsync {</div><div class="">&nbsp; &nbsp; &nbsp; let result = await callee.longRunningOperation()</div><div class="">&nbsp; &nbsp; &nbsp; // do something with result and maybe state</div><div class="">&nbsp; &nbsp; }</div><div class="">&nbsp; }</div><div class="">&nbsp; actor func bar() {</div><div class="">&nbsp; &nbsp; // modify actor state</div><div class="">&nbsp; }</div><div class="">}</div></div></div></div></blockquote><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;">As currently proposed, the “// do something with result and maybe state” line would likely run on Callee’s queue, not Caller’s queue. I still strongly believe that this behavior should be reconsidered.</div></div></blockquote><blockquote type="cite" class=""><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;">It does, however, bring up some interesting questions about how actors interact with themselves. One of the rules laid out in Chris’s document says that “local state and non-actor&nbsp;methods may only be accessed by methods defined lexically on the actor or in an extension to it (whether they are marked&nbsp;actor&nbsp;or otherwise).” That means it would be allowed for the code in foo() to access state and call non-actor methods, even after the await. As proposed that would be unsafe, and since the queue is an implementation detail inaccessible to your code there wouldn’t be a straightforward way to get back on the right queue to make it safe. I presume you could call another actor method to get back on the right queue, but having to do that explicitly after every await in an actor method seems tedious and error prone.</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;">In order to have strong safety guarantees for actors you would want to ensure that all the code that has access to the state runs on the actor’s queue. There are currently two holes I can think of that would prevent us from having that protection: await and escaping blocks. await could be made safe if it were changed to return to the calling queue. Maybe escaping blocks could be restricted to only calling actor methods.</div></div></blockquote><div class=""><br class=""></div>Yes, I think it is mandatory that we continue on the callers queue after an `await ` on some actor method.</div><div class=""><br class=""></div><div class="">If you `await` on a non-actor-method though, you would have to changes queues manually if needed.</div><div class=""><br class=""></div><div class="">Any `actor` should have a `let actorQueue: DispatchQueue` property so that we can call in these cases:</div><div class=""><br class=""></div><div class="">```await actorQueue.asyncCoroutine()``` as mentioned in the manifesto.</div></div></div></blockquote><br class=""></div><div style="font-family: Helvetica; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">Wouldn't that be really confusing though? That awaiting certain methods would bring us back to the actor's queue but awaiting others would require manual queue hopping? What if the compiler was to always generate the 'await actorQueue.asyncCoroutine()' queue hopping code after awaiting on an async/actor method?</div></div></blockquote><br class=""></div><div>Adding a bit more about that: I think it doesn't matter what the callee is (async vs. actor). What matters is we're calling from an actor method and the compiler should guarantee that we're running in the context of the actor's queue. Therefore I would tend to think there should be no need for manual queue hopping. The compiler should just take care of it.</div><br class=""><div class="">Thomas</div><div class=""><br class=""></div></body></html>