eloots opened a new pull request, #741:
URL: https://github.com/apache/incubator-pekko/pull/741

   - Use InteractionPatternsSpec as an example for applying Scala 3's Union 
types to symplify actor code
     - Remove response message wrapper & adapter
     - Use the union of the actor's public protocol (the `Translate` message 
(the only member of the `Command` ADT) and the possible responses from the 
backend (messages `JobStarted`, `JobProgress`, and `JobCompleted`): `private 
type CommandAndResponse = Command | Backend.Response`
     - Instead of utilising the message adaptor `ActorRef` in the `replyTo` 
field of the message sent to the backend, `context.self` is used instead
     - The internal (extended) `Behavior[CommandAndResponse]` is narrowed to 
`Behavior[Command]` at creation time
   
   The diffs between the original and the new version:
   
   ```bash
   136d139
   <         private final case class WrappedBackendResponse(response: 
Backend.Response) extends Command
   137a141,142
   >         private type CommandAndResponse = Command | Backend.Response
   >
   139,141c144
   <           Behaviors.setup[Command] { context =>
   <             val backendResponseMapper: ActorRef[Backend.Response] =
   <               context.messageAdapter(rsp => WrappedBackendResponse(rsp))
   ---
   >           Behaviors.setup[CommandAndResponse] { context =>
   143,144c146,147
   <             def active(inProgress: Map[Int, ActorRef[URI]], count: Int): 
Behavior[Command] = {
   <               Behaviors.receiveMessage[Command] {
   ---
   >             def active(inProgress: Map[Int, ActorRef[URI]], count: Int): 
Behavior[CommandAndResponse] = {
   >               Behaviors.receiveMessage[CommandAndResponse] {
   147c150
   <                   backend ! Backend.StartTranslationJob(taskId, site, 
backendResponseMapper)
   ---
   >                   backend ! Backend.StartTranslationJob(taskId, site, 
context.self)
   150,162c153,162
   <                 case wrapped: WrappedBackendResponse =>
   <                   wrapped.response match {
   <                     case Backend.JobStarted(taskId) =>
   <                       context.log.info("Started {}", taskId)
   <                       Behaviors.same
   <                     case Backend.JobProgress(taskId, progress) =>
   <                       context.log.info2("Progress {}: {}", taskId, 
progress)
   <                       Behaviors.same
   <                     case Backend.JobCompleted(taskId, result) =>
   <                       context.log.info2("Completed {}: {}", taskId, result)
   <                       inProgress(taskId) ! result
   <                       active(inProgress - taskId, count)
   <                   }
   ---
   >                 case Backend.JobStarted(taskId) =>
   >                   context.log.info("Started {}", taskId)
   >                   Behaviors.same
   >                 case Backend.JobProgress(taskId, progress) =>
   >                   context.log.info2("Progress {}: {}", taskId, progress)
   >                   Behaviors.same
   >                 case Backend.JobCompleted(taskId, result) =>
   >                   context.log.info2("Completed {}: {}", taskId, result)
   >                   inProgress(taskId) ! result
   >                   active(inProgress - taskId, count)
   167c167
   <           }
   ---
   >           }.narrow
   ```


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