Last active
January 4, 2016 06:39
-
-
Save jmazin/8583395 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name := "valvar" | |
scalaVersion := "2.10.2" | |
libraryDependencies ++= Seq( | |
"com.typesafe.akka" %% "akka-actor" % "2.2.3", | |
"com.typesafe.akka" %% "akka-testkit" % "2.2.3") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package valvar | |
import akka.actor.Actor | |
import akka.actor.Props | |
import collection.mutable.MutableList | |
import scala.concurrent.duration._ | |
import scala.concurrent.ExecutionContext.Implicits.global | |
object Logger { | |
case class Result(list: List[Int]) | |
case class ResultML(list: MutableList[Int]) | |
case class Log(list: List[Int]) | |
case class LogML(list: MutableList[Int]) | |
} | |
class Logger extends Actor { | |
import Logger._ | |
def receive: Receive = { | |
case Result(list) => { | |
context.system.scheduler.scheduleOnce(1000 millis, self, Log(list)) | |
} | |
case ResultML(list) => { | |
context.system.scheduler.scheduleOnce(1000 millis, self, LogML(list)) | |
} | |
case Log(list) => println(list.mkString("Received var list: ", ", ", "")) | |
case LogML(list) => println(list.mkString("Received mutable val list: ", ", ", "")) | |
} | |
} | |
class Main extends Actor { | |
import Logger._ | |
val logger = context.actorOf(Props[Logger], "logger") | |
var varL = List(1, 2, 3) | |
val valML = MutableList(1, 2, 3) | |
println(varL.mkString("sent var list: ", ", ", "")) | |
println(valML.mkString("sent mutable val list: ", ", ", "")) | |
logger ! Result(varL) | |
logger ! ResultML(valML) | |
varL = varL :+ 23 | |
valML += 23 | |
println(varL.mkString("updated var list: ", ", ", "")) | |
println(valML.mkString("updated mutable val list: ", ", ", "")) | |
def receive = { case _ => } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sent var list: 1, 2, 3 | |
sent mutable val list: 1, 2, 3 | |
updated var list: 1, 2, 3, 23 | |
updated mutable val list: 1, 2, 3, 23 | |
Received var list: 1, 2, 3 | |
Received mutable val list: 1, 2, 3, 23 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment