Skip to content

Instantly share code, notes, and snippets.

@nicolasff
Created January 13, 2009 10:29
Show Gist options
  • Save nicolasff/46392 to your computer and use it in GitHub Desktop.
Save nicolasff/46392 to your computer and use it in GitHub Desktop.
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