Skip to content

Commit

Permalink
replyTo pattern.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabi Volpe committed Aug 5, 2016
1 parent 2a76064 commit b1bdfb5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 20 deletions.
12 changes: 3 additions & 9 deletions src/main/scala/com/gvolpe/typed/ReplyToPatternDemo.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.gvolpe.typed

import akka.actor.ActorSystem
import com.gvolpe.typed.actor.{BrokenReplyToPatternActor, ReplyToPatternActor}
import com.gvolpe.typed.actor.ReplyToPatternActor
import de.knutwalker.akka.typed._

import scala.concurrent.ExecutionContext.Implicits.global
Expand All @@ -11,20 +11,14 @@ object ReplyToPatternDemo extends App {

implicit val system = ActorSystem("typed-actors-demo")

case class MyMessage(payload: String)
case class MyMessage(payload: String)(val replyTo: ActorRef[MyResponse])
case class MyResponse(payload: String)

import akka.actor.ActorDSL._
val box = inbox()

val brokenReplyToPatternActor: ActorRef[MyMessage] = Typed[BrokenReplyToPatternActor].create()
box.send(brokenReplyToPatternActor.untyped, MyMessage("ReplyTo Pattern!"))

val result: Any = box.receive(1.second)
// val MyResponse(result) = box.receive(1.second) // This will throw a MatchError in Runtime!!!

val replyToPatternActor: ActorRef[MyMessage] = Typed[ReplyToPatternActor].create()
box.send(replyToPatternActor.untyped, MyMessage("ReplyTo Pattern!"))
box.send(replyToPatternActor.untyped, MyMessage("ReplyTo Pattern!")(box.receiver.typed))

val MyResponse(response) = box.receive(1.second) // Now it works!
println(response)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import de.knutwalker.akka.typed._

case class ReplyToPatternActor() extends TypedActor.Of[MyMessage] {
override def typedReceive: TypedReceive = {
case m@MyMessage(payload) => sender() ! MyResponse(payload)
case m@MyMessage(payload) => m.replyTo ! MyResponse(payload)
// case m: MyMessage => m.replyTo ! m.payload // This does not compile!
}
}

0 comments on commit b1bdfb5

Please sign in to comment.