Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import scala.actors.Actor
- import scala.actors.Actor._
- class Stage1(val next:Actor) extends Actor {
- def act() {
- while (true) {
- receive {
- case n: Int => next ! n*n
- }
- }
- }
- }
- class Stage2(val next:Actor) extends Actor {
- def act() {
- while (true) {
- receive {
- case n: Int => next ! n.toString
- }
- }
- }
- }
- class Stage3 extends Actor {
- def act() {
- while (true) {
- receive {
- case s: String => println(s.length)
- }
- }
- }
- }
- Output:
- scala> val s3 = new Stage3; val s2 = new Stage2(s3); val s1 = new Stage1(s2); (1 to 10) foreach { s1 ! _ }
- 1
- 1
- 1
- 2
- 2
- 2
- 2
- 2
- 2
- 3
Add Comment
Please, Sign In to add comment