Cleaned-up actor examples. Added OrElse example.
git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@9242 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
parent
395d2411a3
commit
93e24c8bb8
|
@ -1,7 +1,7 @@
|
|||
package examples.actors
|
||||
|
||||
import scala.actors.Actor._
|
||||
import scala.actors.Actor
|
||||
import scala.actors.Actor._
|
||||
|
||||
case object Stop
|
||||
|
||||
|
@ -18,7 +18,7 @@ object Links extends Application {
|
|||
|
||||
def top(a: Actor, n: int): Actor = actor {
|
||||
Console.println("starting actor " + n + " (" + Thread.currentThread() + ")")
|
||||
//self.trapExit = true
|
||||
self.trapExit = true
|
||||
link(a)
|
||||
while (true) {
|
||||
receive {
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
// Modified by Philipp Haller to use Scala's event-based actors.
|
||||
package examples.actors
|
||||
|
||||
import scala.actors._
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package examples.actors
|
||||
|
||||
import scala.actors._
|
||||
import scala.actors.Actor._
|
||||
|
||||
object OrElse {
|
||||
def main(args: Array[String]) = {
|
||||
actor {
|
||||
val b1 = new Channel[int]
|
||||
val b2 = new Channel[int]
|
||||
b2 ! 42
|
||||
val item = { b1.receive {case any => any}
|
||||
} orElse {
|
||||
b2.receive {case any => any} }
|
||||
|
||||
Console.println("" + item)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,7 +16,6 @@ object Seq extends Application {
|
|||
react {
|
||||
case A => scala.Console.println("2nd reactor got A")
|
||||
}
|
||||
()
|
||||
}
|
||||
}
|
||||
a ! A
|
||||
|
|
Loading…
Reference in New Issue