Skip to content

Commit

Permalink
feat: streamlined approach for Behaviors apache#1444
Browse files Browse the repository at this point in the history
  • Loading branch information
Roiocam committed Aug 23, 2024
1 parent 60c480a commit dba3672
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,27 @@ object Behaviors {
def receiveMessage[T](onMessage: pekko.japi.Function[T, Behavior[T]]): Behavior[T] =
new BehaviorImpl.ReceiveBehavior((_, msg) => onMessage.apply(msg))

/**
* Simplified version of [[receiveMessage]] with only a single argument - the message
* to be handled, but it doesn't produce a return value of next behavior.
* Useful for when the behavior doesn't want to change in runtime.
*
* Construct an actor behavior that can react to incoming messages but not to
* lifecycle signals. After spawning this actor from another actor (or as the
* guardian of an [[pekko.actor.typed.ActorSystem]]) it will be executed within an
* [[ActorContext]] that allows access to the system, spawning and watching
* other actors, etc.
*
* Compared to using [[AbstractBehavior]] this factory is a more functional style
* of defining the `Behavior`. Processing the next message will not result in
* different behavior than this one
*/
def receiveMessage[T](onMessage: pekko.japi.Procedure[T]): Behavior[T] =
new BehaviorImpl.ReceiveBehavior((_, msg) => {
onMessage.apply(msg)
same[T]
})

/**
* Construct an actor behavior that can react to both incoming messages and
* lifecycle signals. After spawning this actor from another actor (or as the
Expand Down

0 comments on commit dba3672

Please sign in to comment.