alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (t3412-channel.scala)

This example Scala source code file (t3412-channel.scala) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Scala tags/keywords

array, c, c, channel, channel, int, int, list, list, test, unit

The Scala t3412-channel.scala source code

import scala.actors._, scala.actors.Actor._, scala.actors.Futures._

object Test {

  def main(args: Array[String]) {

    actor {
      val C: Channel[Int] = new Channel[Int](self)

      def respondAll(fts: List[Future[Int]], cnt: Int): Unit =
        fts match {
          case List() => C ! 0
          case ft :: rest =>
            if (cnt % 100 == 0)
              println(ft())
            respondAll(rest, cnt + 1)
        }

      actor {
        val fts = for (_ <- 1 to 1000)
                  yield C !! (3, {case x: Int => x})

        actor {
          respondAll(fts.toList, 0)
        }
      }

      loop {
        C.react {
          case 0 => exit()
          case i => reply(i * 2)
        }
      }
    }

  }

}

Other Scala examples (source code examples)

Here is a short list of links related to this Scala t3412-channel.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.