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

Scala example source code file (channels.scala)

This example Scala source code file (channels.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

application, ch1, ch2, ch2, channel, channel, ich1, ich2, ich2, int, msg, msg

The Scala channels.scala source code

package examples.actors

import scala.actors._
import scala.actors.Actor._

object channels extends Application {
  case class Msg(ch1: Channel[Int], ch2: Channel[String])

  val a = actor {
    val Ch1 = new Channel[Int]
    val Ch2 = new Channel[String]

    b ! Msg(Ch1, Ch2)

    val ICh1 = Ch1.asInstanceOf[InputChannel[Int]]
    val ICh2 = Ch2.asInstanceOf[InputChannel[String]]

    react {
      case ICh1 ! (x: Int) =>
        val r = x + 21
        println("result: "+r)
      case ICh2 ! y =>
        println("received: "+y)
    }
  }

  val b = actor {
    react {
      case Msg(ch1, ch2) => ch1 ! 21
    }
  }
}

Other Scala examples (source code examples)

Here is a short list of links related to this Scala channels.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.