He-Pin opened a new pull request, #3684:
URL: https://github.com/apache/pekko/pull/3684

   ### Motivation
   
   A command handler can select between persisting and replying, replying 
without persistence, or explicitly not replying. After that decision, a caller 
cannot append a common callback through the staged reply-effect API introduced 
in #3682. Recording a metric or sending a notification requires duplicating the 
callback in each branch or moving it before the reply.
   
   Add `thenRun` to that stage, while making `thenStop` end callback 
composition:
   
   ```scala
   handleCommand(state, command)
     .thenRun(updatedState => recordMetric(updatedState))
     .thenStop()
   ```
   
   The helper returns `ReplyEffectWithStop`. `thenStop().thenRun(...)` must not 
compile.
   
   ### Modification
   
   - Declare `thenRun` on `ReplyEffectOps`, returning its recursive `Self` 
type: Scala's state callback and Java's state and no-argument overloads, for 
both event-sourced and durable-state persistence. Mark all new methods `@since 
2.0.0`.
   - Change `ReplyEffectWithStop.thenStop()` to return the base `ReplyEffect`. 
This rejects callbacks after stopping, including through `thenUnstashAll`, 
while `thenRun(...).thenUnstashAll().thenStop()` retains the expected stage. 
`stash()` continues to expose only the base type.
   - Keep traits abstract and implement the Java overloads in `EffectImpl`. 
Make the existing Java `EffectBuilder.thenRun` methods overridable while 
retaining their bodies and descriptors. The existing subtype callback 
adaptation is reused; no effect downcasts or runtime stage checks are 
introduced.
   - Add matching Scala and Java tests for persistence/reply/callback ordering, 
common callbacks after accepted and rejected branches, both no-reply entry 
points, generic `Self` helpers, and stopping after callbacks. Add compile-time 
rejection coverage for stopped, stashed, and widened effects.
   - Update both persistence guides with the use case, type restrictions, and 
existing at-most-once side-effect guarantees. Sending a reply does not wait for 
the recipient to receive or process it.
   
   ### Result
   
   Callers can append callbacks after choosing a reply without losing the 
ability to unstash or stop. Stopping the reply-effect chain removes callback 
capabilities. This adds no new trait and changes no runtime side-effect 
ordering; existing `EffectBuilder` chaining remains outside this reply-stage 
restriction.
   
   **Stacked on #3682 at `c00fbb3376d47b8ec28abe151673207ec5f4e71e`.** The base 
branch `stack/3682-reply-effect-then-stop` mirrors that exact commit so this PR 
shows only the incremental change and runs upstream CI. Keep this PR in draft 
until the parent merges; then rebase and retarget to `main` before merging. Do 
not merge into the temporary stack base.
   
   ### Tests
   
   - Isolated Scala 2.13 compilation of the eight effect API/implementation 
sources and all four new test files: passed.
   - Scala and `javac` client probes: valid generic/fluent chains compile; 10 
Scala and 20 Java invalid chains are rejected. Restoring the old `thenStop` 
return type makes the stopped-chain probes compile, demonstrating the 
regression check. Positive `thenRun` probes fail against the parent API as 
expected.
   - Direct MiMa 1.2.1 probe against compiled `origin/main` sources: the same 
22 findings covered by the parent's exact filters; no additional filter added. 
Published-baseline cross-version MiMa remains for CI.
   - `scalafmt --mode diff-ref=c00fbb3376d47b8ec28abe151673207ec5f4e71e` and 
`--list`: passed.
   - `sbt headerCreateAll javafmtAll` (JDK 17), followed by `sbt 
+headerCheckAll javafmtCheckAll checkCodeStyle`: passed.
   - `sbt sortImports`: environment/tool linkage failure in `stream-tests` and 
`multi-node-testkit` (`scala.meta.package$.Input()`); unrelated generated edits 
removed. Subsequent code-style checks passed.
   - `git diff --check`: passed. Auditable Qoder stdout review: no must-fix 
findings.
   - Full runtime tests, Scala 3/next, `validatePullRequest`, 
published-baseline MiMa, and Paradox: delegated to remote CI; pending. No local 
full-suite runtime result claimed.
   
   ### References
   
   Refs #3682, Refs #3683
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to