Tomassino-ibm commented on code in PR #1919:
URL: https://github.com/apache/pekko/pull/1919#discussion_r2189438391


##########
persistence-typed/src/main/scala/org/apache/pekko/persistence/typed/state/internal/Running.scala:
##########
@@ -100,11 +122,37 @@ private[pekko] object Running {
         else Behaviors.unhandled
     }
 
-    def onCommand(state: RunningState[S], cmd: C): Behavior[InternalProtocol] 
= {
-      val effect = setup.commandHandler(state.state, cmd)
-      val (next, doUnstash) = applyEffects(cmd, state, 
effect.asInstanceOf[EffectImpl[S]]) // TODO can we avoid the cast?
-      if (doUnstash) tryUnstashOne(next)
-      else next
+    def onCommand(state: RunningState[S, C], cmd: C): 
Behavior[InternalProtocol] = {
+      def callApplyEffects(rs: RunningState[S, C], c: C) = {
+        val effect = setup.commandHandler(rs.state, c)
+
+        applyEffects(c, rs, effect.asInstanceOf[EffectImpl[S]]) // TODO can we 
avoid the cast?
+      }
+
+      var applyEffectsRetval: (Behavior[InternalProtocol], Boolean) = 
callApplyEffects(state, cmd)
+
+      var retVal: Option[Behavior[InternalProtocol]] = None
+
+      while (retVal.isEmpty) {

Review Comment:
   I'll also try to change this from a loop to a tail recursive functio



##########
persistence-typed/src/main/scala/org/apache/pekko/persistence/typed/state/internal/Running.scala:
##########
@@ -100,11 +122,37 @@ private[pekko] object Running {
         else Behaviors.unhandled
     }
 
-    def onCommand(state: RunningState[S], cmd: C): Behavior[InternalProtocol] 
= {
-      val effect = setup.commandHandler(state.state, cmd)
-      val (next, doUnstash) = applyEffects(cmd, state, 
effect.asInstanceOf[EffectImpl[S]]) // TODO can we avoid the cast?
-      if (doUnstash) tryUnstashOne(next)
-      else next
+    def onCommand(state: RunningState[S, C], cmd: C): 
Behavior[InternalProtocol] = {
+      def callApplyEffects(rs: RunningState[S, C], c: C) = {
+        val effect = setup.commandHandler(rs.state, c)
+
+        applyEffects(c, rs, effect.asInstanceOf[EffectImpl[S]]) // TODO can we 
avoid the cast?
+      }
+
+      var applyEffectsRetval: (Behavior[InternalProtocol], Boolean) = 
callApplyEffects(state, cmd)
+
+      var retVal: Option[Behavior[InternalProtocol]] = None
+
+      while (retVal.isEmpty) {

Review Comment:
   I'll also try to change this from a loop to a tail recursive function



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@pekko.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@pekko.apache.org
For additional commands, e-mail: notifications-h...@pekko.apache.org

Reply via email to