diff options
author | Philipp Haller <hallerp@gmail.com> | 2006-11-03 16:32:58 +0000 |
---|---|---|
committer | Philipp Haller <hallerp@gmail.com> | 2006-11-03 16:32:58 +0000 |
commit | bce3c6001fa9b361cae9019d5a4d96aaf6d7e103 (patch) | |
tree | 5ed225b5e380545b1405ede96343eb8bd72ca1c6 /docs/examples/actors/Joins.scala | |
parent | bc752a61fed299942cce659f075702ef9e4fb205 (diff) | |
download | scala-bce3c6001fa9b361cae9019d5a4d96aaf6d7e103.tar.gz scala-bce3c6001fa9b361cae9019d5a4d96aaf6d7e103.tar.bz2 scala-bce3c6001fa9b361cae9019d5a4d96aaf6d7e103.zip |
Added new actor example.
Diffstat (limited to 'docs/examples/actors/Joins.scala')
-rw-r--r-- | docs/examples/actors/Joins.scala | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/docs/examples/actors/Joins.scala b/docs/examples/actors/Joins.scala index 29ff220709..85105ec178 100644 --- a/docs/examples/actors/Joins.scala +++ b/docs/examples/actors/Joins.scala @@ -3,11 +3,11 @@ package examples.actors import scala.actors.Actor._ abstract class Producer[T] extends Iterator[T] { - - protected def produce(x: T): unit = coordinator !? HasValue(x) + protected def produce(x: T): unit = coordinator ! HasValue(x) protected def produceValues: unit - def hasNext: boolean = { setCurrent(); !current.isEmpty } + def hasNext = { setCurrent(); !current.isEmpty } + def next: T = { setCurrent() val res = current.get @@ -16,7 +16,8 @@ abstract class Producer[T] extends Iterator[T] { } private var current: Option[T] = null - private def setCurrent() = if (current == null) current = (coordinator !? Next).asInstanceOf[Option[T]] + private def setCurrent() = + if (current == null) current = (coordinator !? Next).asInstanceOf[Option[T]] private case class HasValue(value: T) private case object Next @@ -24,26 +25,23 @@ abstract class Producer[T] extends Iterator[T] { private case object Continue private val coordinator = actor { - while (true) { + while (true) receive { case Next => reply { receive { case HasValue(v) => - reply() Some(v) case Done => None } } } - } } actor { produceValues - coordinator !? Done - () + coordinator ! Done } } |