Add some nesting samples and clarifications to the docs #28659
This commit is contained in:
parent
fc6dd5f049
commit
1dc715ddc8
3 changed files with 121 additions and 2 deletions
|
|
@ -457,6 +457,29 @@ of using `newReceiveBuilder`. Implement the `receiveMessage` and `receiveSignal`
|
|||
|
||||
@@@
|
||||
|
||||
## Nesting setup
|
||||
|
||||
When an actor behavior needs more than one of `setup`, `withTimers` and `withStash` the methods can be nested to access
|
||||
the needed dependencies:
|
||||
|
||||
Scala
|
||||
: @@snip [StyleGuideDocExamples.scala](/akka-actor-typed-tests/src/test/scala/docs/akka/typed/StyleGuideDocExamples.scala) { #nesting }
|
||||
|
||||
Java
|
||||
: @@snip [StyleGuideDocExamples.java](/akka-actor-typed-tests/src/test/java/jdocs/akka/typed/StyleGuideDocExamples.java) { #nesting }
|
||||
|
||||
The order of the nesting does not change the behavior as long as there is no additional logic in any other function than the innermost one.
|
||||
It can be nice to default to put `setup` outermost as that is the least likely block that will be removed if the actor logic changes.
|
||||
|
||||
Note that adding `supervise` to the mix is different as it will restart the behavior it wraps, but not the behavior around itself:
|
||||
|
||||
Scala
|
||||
: @@snip [StyleGuideDocExamples.scala](/akka-actor-typed-tests/src/test/scala/docs/akka/typed/StyleGuideDocExamples.scala) { #nesting-supervise }
|
||||
|
||||
Java
|
||||
: @@snip [StyleGuideDocExamples.java](/akka-actor-typed-tests/src/test/java/jdocs/akka/typed/StyleGuideDocExamples.java) { #nesting-supervise }
|
||||
|
||||
|
||||
## Additional naming conventions
|
||||
|
||||
Some naming conventions have already been mentioned in the context of other recommendations, but here
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue