<div dir="ltr">Hi,<div><br></div><div>to anyone interested, I put some experimental Actor demo here: </div><div><br></div><div><a href="https://github.com/frameworklabs/actress">https://github.com/frameworklabs/actress</a></div><div><br></div><div>The motivation of it is to have some setup to be able to play with async actor methods for further discussions. As we don't have async/await right now, I use Continuation Passing Style instead. I think this demo helps to understand the difference between the actors dispatch queue and its message/activity queue.</div><div><br></div><div>Also, I added `Behaviour` support to it, as I think this is a necessary part unless we introduce a `wait-for-any-message-in()` method which can be placed anywhere inside an actor-method. </div><div><br></div><div>Obviously, topics like securely passing arguments, master-worker setup, actor lookup, remote capabilities etc. are not touched here.</div><div><br></div><div>Cheers</div><div>Marc<br><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Aug 20, 2017 at 9:43 PM, Marc Schlichte via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div class="gmail-HOEnZb"><div class="gmail-h5">Hi,<br>
<br>
here are some high-level thoughts on extending Actors with Behaviors and Signals.<br>
<br>
Actors + Behaviors:<br>
<br>
The set of messages an Actor might handle at a time is defined by the current behavior which can be changed with the `become` instruction:<br>
<br>
```<br>
behavior B1 {<br>
message m1()<br>
message m2() -> Int<br>
}<br>
<br>
behavior B2 {<br>
message m3(str: String)<br>
}<br>
<br>
actor A1: B1, B2 {<br>
init() {<br>
become B1<br>
}<br>
message m1() {<br>
print(„m1“)<br>
become B2<br>
}<br>
message m2() -> Int {<br>
print(„m2“)<br>
return 1<br>
}<br>
message m3(str: String) {<br>
print(„m3\(str)“)<br>
become B1<br>
}<br>
}<br>
```<br>
<br>
`behavior` is a kind of `protocol` which contains only actor functions.<br>
<br>
BTW, to allow for some bikeshed discussions here - I propose to use `message` instead of `actor func` - like preferring `actor` to `actor class`.<br>
<br>
Behaviors are optional - if you don’t define/adopt behaviors, all messages in an actor are part of an implicit behavior.<br>
<br>
If a message arrives, which is not part of the current behavior, it will stay in the message queue but ignored until a supporting behavior becomes current again.<br>
<br>
To allow the reception of another message while a message handler is currently suspended in some async call - maybe communicating with another actor - an `interleaved` modifier for messages might be introduced. These interleaved messages are not allowed to change the current behavior though.<br>
<br>
Actors + Signals:<br>
<br>
Like classes, which often provide reactive APIs (via `delegates`, `KVO`, `NotificationCenter`, `Observables`, …) for unsolicited events, Actors will need a way to send messages to unknown other Actors.<br>
<br>
I thus propose the introduction of Signals:<br>
<br>
```<br>
actor A2 {<br>
signal s1(val: Int)<br>
<br>
message m1(val: Int) {<br>
print(„m1“)<br>
s1(val)<br>
}<br>
}<br>
<br>
actor A3 {<br>
message m1(val: Int) { … }<br>
message m2(str: String) { … }<br>
}<br>
<br>
let a2 = A2()<br>
let a3 = A3()<br>
a2.s1.connect(to: a3.m1)<br>
```<br>
<br>
Signals might also support stream functions like `map`, `filter`, `throttle`, `distinctUntilChanged`, etc, to allow for reactive value transformations of signals sent by actors:<br>
<br>
```<br>
a2.s1.throttle(interval: 0.2).map { String($0) }.connect(to: a3.m2)<br>
```<br>
<br>
Cheers<br>
Marc<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
</div></div>______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
</blockquote></div><br></div></div></div>