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


##########
persistence-typed/src/main/scala/org/apache/pekko/persistence/typed/internal/Running.scala:
##########
@@ -268,15 +288,43 @@ 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[E, 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[E, 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'm not sure I understand the question: this loop basically replaces the 
recursion, so if the problem you expect is to keep a thread busy for too long, 
then that was probably already happening before (with recursion). The `retVal` 
variable is the final behavior returned by `onCommand`, it is an option so that 
it can be used as the exit condition of the loop: it is only set to `Some` if 
either `doUnstash` is false or the call to `tryUnstashOne` is not recursive 
(i.e. `state.unstashRecurrenceState` is not set in `onMessage`)



-- 
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