I have an asynchronous control-flow like the following:
ActorA ! DoA(dataA, callback1, callbackOnErrorA)
def callback1() = {
...
ActorB ! DoB(dataB, callback2, callbackOnErrorB)
}
def callback2() = {
ActorC ! DoC(dataC, callback3, callbackOnErrorC)
}
...
How would I divide this flow into several parts (continuations) and sequentially dispatch these to different actors (or threads/tasks) while maintaining the overall state?
Any hint appreciated, Thanks
I like to use
scalaz.concurrent.Promise
. This example isn't exactly like the one in your question, but it gives you the idea.Output:
You'll find an introduction to Scalaz concurrency in this presentation from Runar.
This approach isn't as flexible as Actors, but composes better and can't deadlock.
See Akka's Futures and how to compose them or scalaz's Promises, they are nearly the same, there are only slight differences.
This is very simplified, but shows how to split up a single control flow among three actors, passing the state along to each: