|
Scala example source code file (links.scala)
The Scala links.scala source codepackage examples.actors import scala.actors.{Actor, Exit} import scala.actors.Actor._ object links extends Application { case object Stop actor { val start = link(p(2)) start ! Stop } def p(n: Int): Actor = if (n == 0) top1() else top(p(n-1), n) def top(a: Actor, n: Int): Actor = actor { println("starting actor " + n + " (" + self + ")") self.trapExit = true link(a) loop { receive { case ex @ Exit(from, reason) => println("Actor " + n + " received " + ex) exit('finished) case any => { println("Actor " + n + " received " + any) a ! any } } } } def top1(): Actor = actor { println("starting last actor" + " (" + self + ")") receive { case Stop => println("Last actor now exiting") exit('abnormal) case any => println("Last actor received " + any) top1() } } } Other Scala examples (source code examples)Here is a short list of links related to this Scala links.scala source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
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.