diff options
author | Philipp Haller <hallerp@gmail.com> | 2006-10-02 15:31:37 +0000 |
---|---|---|
committer | Philipp Haller <hallerp@gmail.com> | 2006-10-02 15:31:37 +0000 |
commit | 8d3d085f4bc64bfe019e49675e64073e5a73f60a (patch) | |
tree | 948bca5d3edef0182762cfd703850405e90b21be /docs/examples/actors/Joins.scala | |
parent | 6c710d403e147a81eeb739e20aba07ba47c45b70 (diff) | |
download | scala-8d3d085f4bc64bfe019e49675e64073e5a73f60a.tar.gz scala-8d3d085f4bc64bfe019e49675e64073e5a73f60a.tar.bz2 scala-8d3d085f4bc64bfe019e49675e64073e5a73f60a.zip |
Clean-ups and new example for usage of input ch...
Clean-ups and new example for usage of input channels.
Diffstat (limited to 'docs/examples/actors/Joins.scala')
-rw-r--r-- | docs/examples/actors/Joins.scala | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/docs/examples/actors/Joins.scala b/docs/examples/actors/Joins.scala index 7ea2a50e11..637cb5d092 100644 --- a/docs/examples/actors/Joins.scala +++ b/docs/examples/actors/Joins.scala @@ -11,29 +11,29 @@ abstract class Producer[T] extends Iterator[T] { def next: T = { setCurrent() val res = current.get - current = (coordinator !? Next()).asInstanceOf[Option[T]] + current = (coordinator !? Next).asInstanceOf[Option[T]] res } 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 class Next - private case class Done - private case class Continue + private case class HasValue(value: T) + private case object Next + private case object Done + private case object Continue /** A thread-based coordinator */ private val coordinator = actor { while (true) { receive { - case Next() => + case Next => reply { receive { case HasValue(v) => reply() Some(v) - case Done() => + case Done => None } } @@ -43,7 +43,8 @@ abstract class Producer[T] extends Iterator[T] { actor { produceValues - coordinator !? Done() + coordinator !? Done + () } } |