Skip to content

Instantly share code, notes, and snippets.

@johanandren
Created June 22, 2017 15:37
Show Gist options
  • Save johanandren/627ff7011ccf32ff0ff40a16f58602d9 to your computer and use it in GitHub Desktop.
Save johanandren/627ff7011ccf32ff0ff40a16f58602d9 to your computer and use it in GitHub Desktop.
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