Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import scala.actors.Actor
- class Foo extends Exception
- abstract class Base extends Actor {
- var myfunc: Option[PartialFunction[Any, Unit]] = None
- def func(f: PartialFunction[Any, Unit]){
- myfunc = Some(f)
- }
- def act {
- loop {
- react {
- case x =>
- try {
- myfunc.foreach(_(x))
- } catch {
- case _ => println("got exception")
- }
- }
- }
- }
- }
- class MyActor extends Base {
- func {
- case "die" => throw new Foo
- case _ => println("nothing...")
- }
- }
- object App {
- def main(args: Array[String]): Unit = {
- val a = new MyActor
- println("starting actor...")
- a.start
- a ! "hello"
- a ! "die"
- a ! "hello"
- }
- }
Add Comment
Please, Sign In to add comment