diff options
author | michelou <michelou@epfl.ch> | 2008-02-14 16:43:18 +0000 |
---|---|---|
committer | michelou <michelou@epfl.ch> | 2008-02-14 16:43:18 +0000 |
commit | ba31aaae833ee9caa33c5d7f713003f901b299eb (patch) | |
tree | 68b7aa6919f647e0f1d36dbf9bda31e41c5bb562 /docs/examples/actors/message.scala | |
parent | 2ba73ce97c64b7ead04a2efc562dbe8ca3b13e6f (diff) | |
download | scala-ba31aaae833ee9caa33c5d7f713003f901b299eb.tar.gz scala-ba31aaae833ee9caa33c5d7f713003f901b299eb.tar.bz2 scala-ba31aaae833ee9caa33c5d7f713003f901b299eb.zip |
updated code
Diffstat (limited to 'docs/examples/actors/message.scala')
-rw-r--r-- | docs/examples/actors/message.scala | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/docs/examples/actors/message.scala b/docs/examples/actors/message.scala index 303dcbe9e1..9158fef695 100644 --- a/docs/examples/actors/message.scala +++ b/docs/examples/actors/message.scala @@ -1,10 +1,11 @@ package examples.actors -import scala.actors._; import scala.actors.Actor._ +import scala.actors._ +import scala.actors.Actor._ object message { - def main(args: Array[String]) = { - val n = try { Integer.parseInt(args(0)) } + def main(args: Array[String]) { + val n = try { args(0).toInt } catch { case _ => println("Usage: examples.actors.message <n>") @@ -14,9 +15,9 @@ object message { val finalSum = n * nActors Scheduler.impl = new SingleThreadedScheduler - def beh(next: Actor, sum: int): unit = + def beh(next: Actor, sum: Int) { react { - case value: int => + case value: Int => val j = value + 1; val nsum = sum + j if (next == null && nsum >= n * j) println(nsum) @@ -25,11 +26,12 @@ object message { if (nsum < n * j) beh(next, nsum) } } + } def actorChain(i: Int, a: Actor): Actor = if (i > 0) actorChain(i-1, actor(beh(a, 0))) else a val firstActor = actorChain(nActors, null) - var i = n; while (i > 0) { firstActor ! 0; i = i-1 } + var i = n; while (i > 0) { firstActor ! 0; i -= 1 } } } |