Skip to content

Instantly share code, notes, and snippets.

@langley
Last active March 31, 2016 07:25

Revisions

  1. langley renamed this gist Dec 22, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. langley created this gist Dec 22, 2013.
    21 changes: 21 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    import akka.actor._
    // need an actor system, make it implicit to it's used by all our repl based actors
    implicit val system = ActorSystem("replActorSystem")

    // this gives us an easy way to define simple actors
    import ActorDSL._

    // here's a simple example of creating an actor
    // Also, this will give us a simple actor that is used to print the
    // results sent back to us from the other actors.
    implicit val sender = actor(new Act { become { case msg => println(msg) } } )

    // Another actor to talk to
    val anotherActor = actor(new Act { become { case msg => sender ! s"I heard you say: $msg" }})

    // Now send the other actor something
    anotherActor ! "a simple string message"

    // And you'll see the below, shown in a comment so you can copy & paste all of this into your repl window
    // scala> I heard you say: a simple string message
    // Note you see the response because of our implicit sender defined above.