diff options
author | michelou <michelou@epfl.ch> | 2004-02-25 12:32:58 +0000 |
---|---|---|
committer | michelou <michelou@epfl.ch> | 2004-02-25 12:32:58 +0000 |
commit | d15a4148ef955469477097129f442d61a6f21116 (patch) | |
tree | 4b0078279ddd7dcdac2ab37c5db871f7674150a9 /sources/examples/computeserver.scala | |
parent | df05d142907eee61ae97ee495de4440b9aea3afc (diff) | |
download | scala-d15a4148ef955469477097129f442d61a6f21116.tar.gz scala-d15a4148ef955469477097129f442d61a6f21116.tar.bz2 scala-d15a4148ef955469477097129f442d61a6f21116.zip |
- renamed to 'computeserver.scala'.
Diffstat (limited to 'sources/examples/computeserver.scala')
-rw-r--r-- | sources/examples/computeserver.scala | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/sources/examples/computeserver.scala b/sources/examples/computeserver.scala new file mode 100644 index 0000000000..f86f41e3ff --- /dev/null +++ b/sources/examples/computeserver.scala @@ -0,0 +1,42 @@ +package examples; + +import concurrent._, concurrent.ops._; + +class ComputeServer(n: Int) { + + private trait Job { + type t; + def task: t; + def ret(x: t): Unit; + } + + private val openJobs = new Channel[Job](); + + private def processor(i: Int): Unit = { + while (true) { + val job = openJobs.read; + Console.println("read a job"); + job.ret(job.task) + } + } + + def future[a](def p: a): () => a = { + val reply = new SyncVar[a](); + openJobs.write{ + new Job { + type t = a; + def task = p; + def ret(x: a) = reply.set(x); + } + } + () => reply.get + } + + spawn(replicate(0, n) { processor }) +} + +object computeserver with Application { + val server = new ComputeServer(1); + val f = server.future(42); + Console.println(f()) +} |