diff options
author | Philipp Haller <hallerp@gmail.com> | 2006-07-14 12:44:35 +0000 |
---|---|---|
committer | Philipp Haller <hallerp@gmail.com> | 2006-07-14 12:44:35 +0000 |
commit | 9d95c090f440956f856468dc59bdfd0ff560314b (patch) | |
tree | 82321355c0bef6f2c495fa30caa1b73331673d88 /docs/examples/actors/customer.scala | |
parent | 56c803d9c5b784d41e4d14b41d18d361e5830b31 (diff) | |
download | scala-9d95c090f440956f856468dc59bdfd0ff560314b.tar.gz scala-9d95c090f440956f856468dc59bdfd0ff560314b.tar.bz2 scala-9d95c090f440956f856468dc59bdfd0ff560314b.zip |
Updated actor examples.
Diffstat (limited to 'docs/examples/actors/customer.scala')
-rw-r--r-- | docs/examples/actors/customer.scala | 34 |
1 files changed, 11 insertions, 23 deletions
diff --git a/docs/examples/actors/customer.scala b/docs/examples/actors/customer.scala index 80c2664130..58ba55b014 100644 --- a/docs/examples/actors/customer.scala +++ b/docs/examples/actors/customer.scala @@ -7,31 +7,21 @@ package examples.actors -import scala.actors._ -import scala.actors.single._ +import scala.actors.single.Actor -abstract class FactorialMessage -case class Factorial(n: int, resTo: Actor) extends FactorialMessage -case class Value(n: int) extends FactorialMessage +case class Factorial(n: int, resTo: Actor) class FactorialProcess extends Actor { override def run: unit = { receive { case Factorial(n, resTo) => if (n == 0) { - Debug.info("Sending Value(1) to " + resTo) - resTo send Value(1) + resTo ! 1 } else { - // spawn process that multiplies - /*val m = spawnReceive({ - case Value(value) => resTo send Value(n * value) - });*/ - val m = new MultiplyActor(n, resTo) - m.start - Debug.info("Sending Factorial(" + (n-1) + ", " + m + ") to " + this) - this send Factorial(n-1, m) + m.start() + this ! Factorial(n-1, m) } run } @@ -41,28 +31,26 @@ class FactorialProcess extends Actor { class MultiplyActor(factor: int, resTo: Actor) extends Actor { override def run: unit = receive { - case Value(value) => - Debug.info("Sending Value(" + factor * value + ") to " + resTo) - resTo send Value(factor * value) - Debug.info("Done sending.") + case value: int => + resTo ! factor * value } } object CustomerPassing { def main(args: Array[String]): unit = { val fac = new FactorialProcess - fac.start + fac.start() val c = new Actor { override def run: unit = { - fac send Factorial(3, this) + fac ! Factorial(3, this) receive { - case Value(value) => + case value: int => System.out.println("Result: " + value) } } } - c.start + c.start() } } |