Created
June 22, 2017 15:37
-
-
Save johanandren/627ff7011ccf32ff0ff40a16f58602d9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import akka.typed.Behavior | |
import akka.typed.scaladsl.Actor._ | |
sealed trait LifecycleCommand | |
object Stop extends LifecycleCommand | |
val lifecycleBehavior: Behavior[LifecycleCommand] = | |
immutable[LifecycleCommand]((ctx, msg) => | |
msg match { | |
case Stop => | |
stopped | |
} | |
) | |
sealed trait CounterCommand | |
object Increase extends CounterCommand | |
val counterBehavior: Behavior[CounterCommand] = | |
deferred[CounterCommand] { (ctx) => | |
var counter = 0 | |
immutable((ctx, msg) => | |
msg match { | |
case Increase => | |
counter += 1 | |
println("Counter " + counter) | |
same | |
} | |
) | |
} | |
// Doesn't exist but the idea is something like | |
val composed: Behavior[CounterCommand | LifecycleCommand] = | |
lifecycleBehavior.orElse(counterBehavior) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment