Actor の link について

いまいち何につかうか良くわかっていなかった link ですが、Scala のフォーラムと、2ch でようやく理解しました。

http://www.nabble.com/Some-Actor-questions-td8906252.html#a8910854

リンクを設定しておくと、リンク先のアクタが終了したときに Exit メッセージを受け取ることができます。*1
これにより、必要であれば複数の関連するアクタを、一緒に終了することができます。
注意点?として link は、リンク元のアクタ内で設定する必要があります。*2
なので、記述としては以下のようになるかと。

val foo = actor {...}
val bar = actor {
  self.trapExit = true
  link(foo)

  loop { react {
    case Msg1 => ...
    case Exit(from, reason) => exit
  }}
}


現バージョンの Actor ライブラリでは、メッセージは Exit ケースクラスによるものですが、今後は例外オブジェクトの受け渡しに対応するために triple に変更するようです。

I want to change the format in the next release because it doesn't allow to pass
exception objects as the reason (which is a good default for uncaught
exceptions), and it introduces another class `Exit', even though a triple
`{'EXIT, from, exc}' would suffice (note `'EXIT' is a `Symbol'). The SVN version
of the actor library (which will become 0.9.4) uses the triple form.

なので、case ('EXIT, from, ex) => .... と書くようになるんでしょうね。

*1:trapExit = true を設定しておく必要があります

*2:this==self であることをチェックしてます