diff options
author | Philipp Haller <hallerp@gmail.com> | 2006-09-29 16:50:44 +0000 |
---|---|---|
committer | Philipp Haller <hallerp@gmail.com> | 2006-09-29 16:50:44 +0000 |
commit | 60b3d90f81cf3f83440725a02afc7dc693fa9ea5 (patch) | |
tree | a441481b4812eb9815db8946dea88dc3d5e08245 /docs/examples/actors/RemoteCounter.scala | |
parent | 499d7f10e23549ef30a61d13fc7f4203145f14f1 (diff) | |
download | scala-60b3d90f81cf3f83440725a02afc7dc693fa9ea5.tar.gz scala-60b3d90f81cf3f83440725a02afc7dc693fa9ea5.tar.bz2 scala-60b3d90f81cf3f83440725a02afc7dc693fa9ea5.zip |
Checked in examples for new actors lib.
Diffstat (limited to 'docs/examples/actors/RemoteCounter.scala')
-rw-r--r-- | docs/examples/actors/RemoteCounter.scala | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/docs/examples/actors/RemoteCounter.scala b/docs/examples/actors/RemoteCounter.scala new file mode 100644 index 0000000000..b52259b6c2 --- /dev/null +++ b/docs/examples/actors/RemoteCounter.scala @@ -0,0 +1,45 @@ +package examples.actors + +import scala.actors.Actor._ +import scala.actors.RemoteActor._ +import scala.actors.{Actor,TcpNode} + +case object Incr +case object Value +case class Result(v: int) + +object RemoteCounter extends Application { + actor { + def loop(value: int): unit = { + Console.println("Value: " + value) + receive { + case Incr => loop(value + 1) + case Value => { sender ! Result(value); loop(value) } + case other => loop(value) + } + } + + alive(9010) + register('counter, self) + loop(0) + } + + actor { + val c = select(TcpNode("127.0.0.1", 9010), 'counter) + + c ! Incr + c ! Incr + + try { Thread.sleep(1000) } catch { + case ie: InterruptedException => + } + + c ! Value + receive { + case Result(v) => { + Console.println("Received result: " + v) + sender ! Incr + } + } + } +} |