-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Labels
enhancementNew feature or requestNew feature or request
Milestone
Description
Embrace a more Kotlinish style, letting the KBehavior type be defined as follows:
object MainActor {
val behavior: KkBehavior<Int> =
setup {
val counterRef = ctx.spawn("counter", Counter.behavior(0))
counterRef `!` Counter.Increment(40)
counterRef `!` Counter.Increment(2)
ctx.log.info("Getting the value of the counter")
counterRef `!` Counter.GetValue(ctx.self)
counterRef `!` Counter.Reset
counterRef `!` Counter.GetValue(ctx.self)
receive {
ctx.log.info("The counter value is $msg")
same()
}
}
}
object Counter {
sealed interface Command
data class Increment(val by: Int) : Command
object Reset : Command
data class GetValue(val replyTo: KActorRef<Int>) : Command
fun behavior(currentValue: Int): KkBehavior<Command> =
receive {
when (msg) {
is Increment -> behavior(currentValue + msg.by)
is Reset -> behavior(0)
is GetValue -> {
msg.replyTo `!` currentValue
same()
}
}
}
}The ctx and msg should be implicitly available in the setup and receive factory methods.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request