Created
January 13, 2009 10:29
-
-
Save nicolasff/46392 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
import scala.actors.Actor | |
import scala.actors.Actor._ | |
case class Inc(amount: Int) | |
case class Value | |
class Counter extends Actor { | |
var counter: Int = 0; | |
def act() = { | |
while (true) { | |
receive { | |
case Inc(amount) => | |
counter += amount | |
case Value => | |
println("Value is "+counter) | |
exit() | |
} | |
} | |
} | |
} | |
object ActorTest extends Application { | |
val counter = new Counter | |
counter.start() | |
for (i <- 0 until 1000000) { | |
counter ! Inc(1) | |
} | |
counter ! Value | |
// Output: Value is 1000000 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment