You can also use "unbecome" and effectively treat an actor's behavior as a stack, popping and pushing receive functions. One cool trick is to bind a value to your receive function:
def receive(foo: Foo): Receive = { ... }
Then you can bind immutable data to a given receive function but think of it as mutable by replacing the current receive function with become().
Comments
Akka actors have a very similar feature, same name. It doesn't swap identities though.
It's actually pretty cool if you think of it as a way to track state without having a mutable variable.
One example is this implementation of the dining philosophers problem:
https://github.com/akka/akka/blob/master/akka-samples/akka-s...
You can also use "unbecome" and effectively treat an actor's behavior as a stack, popping and pushing receive functions. One cool trick is to bind a value to your receive function:
Then you can bind immutable data to a given receive function but think of it as mutable by replacing the current receive function with become().