Inspirations: Scala Actors, Akka, Pykka
Actors live in systems, so let's define ours:
var drama =var sys =
Okay, now let's create a simple actor in our system, with some default behavior:
var actor = sys
And then run it!
actor // 'world'
Right. Now let's see what else we can do. Maybe we need to put and get some value back and forth from the actor. So let's create an actor that does that:
var actor = sys
Wait, what happened here? We defined an initial behavior as a function. These functions catch all the messages, but we'll only be using the first one to set an initial value and put our var in scope.
return or designate a behavior for any message that'll come in the future.
return is essentially overloaded to be the
react method familiar with other actor implementations. Scala users should read
So let's initialize it and use it:
You probably don't want literals all over your code. Don't worry, you can create a proxy and use it as a regular object:
var proxy = actorproxyproxy
Here we create a proxy using
pick on an actor reference. It essentially allows you to pick
methods from the actor. You'll also notice the
? which is used to declare that this method
should be invoked with
ask rather than
There is also a
?? prefix to indicate that the reply is expected to be a future, and that you want to auto-resolve and callback for you.
Hopefully, when we get harmony proxies from ES6 everywhere, this step could be omitted.
Just fork the system and use like local:
var remote = sysvar remoteActor = remoteremoteActor
These and a lot more, can be found in the