Guest User

Untitled

a guest
Oct 15th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. import scala.actors.Actor
  2. import scala.actors.Actor._
  3.  
  4. class Stage1(val next:Actor) extends Actor {
  5. def act() {
  6. while (true) {
  7. receive {
  8. case n: Int => next ! n*n
  9. }
  10. }
  11. }
  12. }
  13.  
  14. class Stage2(val next:Actor) extends Actor {
  15. def act() {
  16. while (true) {
  17. receive {
  18. case n: Int => next ! n.toString
  19. }
  20. }
  21. }
  22. }
  23.  
  24. class Stage3 extends Actor {
  25. def act() {
  26. while (true) {
  27. receive {
  28. case s: String => println(s.length)
  29. }
  30. }
  31. }
  32. }
  33.  
  34. Output:
  35.  
  36. scala> val s3 = new Stage3; val s2 = new Stage2(s3); val s1 = new Stage1(s2); (1 to 10) foreach { s1 ! _ }
  37. 1
  38. 1
  39. 1
  40. 2
  41. 2
  42. 2
  43. 2
  44. 2
  45. 2
  46. 3
Add Comment
Please, Sign In to add comment