Guest User

Untitled

a guest
Jul 20th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. import scala.actors.Actor
  2.  
  3. class Foo extends Exception
  4.  
  5. abstract class Base extends Actor {
  6.  
  7. var myfunc: Option[PartialFunction[Any, Unit]] = None
  8.  
  9. def func(f: PartialFunction[Any, Unit]){
  10. myfunc = Some(f)
  11. }
  12.  
  13. def act {
  14. loop {
  15. react {
  16. case x =>
  17. try {
  18. myfunc.foreach(_(x))
  19. } catch {
  20. case _ => println("got exception")
  21. }
  22. }
  23. }
  24. }
  25. }
  26.  
  27. class MyActor extends Base {
  28. func {
  29. case "die" => throw new Foo
  30. case _ => println("nothing...")
  31. }
  32. }
  33.  
  34.  
  35. object App {
  36. def main(args: Array[String]): Unit = {
  37. val a = new MyActor
  38. println("starting actor...")
  39. a.start
  40.  
  41. a ! "hello"
  42. a ! "die"
  43. a ! "hello"
  44. }
  45.  
  46. }
Add Comment
Please, Sign In to add comment