You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@pekko.apache.org by "Roiocam (via GitHub)" <gi...@apache.org> on 2023/09/24 07:15:59 UTC

[GitHub] [incubator-pekko] Roiocam opened a new issue, #678: intercept definitions hell

Roiocam opened a new issue, #678:
URL: https://github.com/apache/incubator-pekko/issues/678

   <!--
   Please report issues regarding specific projects in their respective issue trackers, e.g.:
    - Pekko HTTP: https://github.com/apache/incubator-pekko-http/issues
    - Pekko Connectors: https://github.com/apache/incubator-pekko-connectors/issues 
    - Pekko Persistence Cassandra Plugin: https://github.com/apache/incubator-pekko-persistence-cassandra/issues
    - ...
   
   Please explain your use case precisely, and if possible provide an example snippet.
   
   Thanks for contributing!
   -->
   
   The contemplation originated from PR #670. 
   
   The implementation of the supervisor is based on a pre-defined BehaviorInterceptor.
   
   When we define multiple interceptors for an actor, the code structure resembles a "callback hell," and it would be beneficial to flatten it for better readability and maintainability.
   
   it also can be used in the supervisor definition.
   
   ```scala
     val initialBehavior: Behavior[Any] = ???
         val interceptor1: BehaviorInterceptor[Any, Any] = ???
         val interceptor2: BehaviorInterceptor[Any, Any] = ???
         val interceptor3: BehaviorInterceptor[Any, Any] = ???
         val interceptor4: BehaviorInterceptor[Any, Any] = ???
         val interceptor5: BehaviorInterceptor[Any, Any] = ???
         val interceptor6: BehaviorInterceptor[Any, Any] = ???
   
         // define-hell
         val finalBehavior = Behaviors
           .intercept(() => interceptor6)(Behaviors
             .intercept(() => interceptor5)(Behaviors
               .intercept(() => interceptor4)(Behaviors
                 .intercept(() => interceptor3)(Behaviors
                   .intercept(() => interceptor2)(Behaviors
                     .intercept(() => interceptor1)(initialBehavior))))))
   
         // or define like this
         val behavior1 = Behaviors.intercept(() => interceptor1)(initialBehavior)
         val behavior2 = Behaviors.intercept(() => interceptor2)(initialBehavior)
         val behavior3 = Behaviors.intercept(() => interceptor3)(initialBehavior)
         val behavior4 = Behaviors.intercept(() => interceptor4)(initialBehavior)
         val behavior5 = Behaviors.intercept(() => interceptor5)(initialBehavior)
         val behavior6 = Behaviors.intercept(() => interceptor6)(initialBehavior)
   
         // it would be better that have a flatten definition
         val finalBehavior = Behaviors.intercepts(initialBehavior)
           .applyInterceptor(interceptor1)
           .applyInterceptor(interceptor2)
           .applyInterceptor(interceptor3)
           .applyInterceptor(interceptor4)
           .applyInterceptor(interceptor5)
           .applyInterceptor(interceptor6)
   ```
   


-- 
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-unsubscribe@pekko.apache.org.apache.org

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


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


[GitHub] [incubator-pekko] Roiocam closed issue #678: Interceptor definitions hell

Posted by "Roiocam (via GitHub)" <gi...@apache.org>.
Roiocam closed issue #678: Interceptor definitions hell
URL: https://github.com/apache/incubator-pekko/issues/678


-- 
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-unsubscribe@pekko.apache.org

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


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


[GitHub] [incubator-pekko] He-Pin commented on issue #678: Interceptor definitions hell

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin commented on issue #678:
URL: https://github.com/apache/incubator-pekko/issues/678#issuecomment-1732517914

   Need an immutable builder pattern for this.


-- 
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-unsubscribe@pekko.apache.org

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


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