Skip to content

Instantly share code, notes, and snippets.

@k4200
Created June 11, 2011 00:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k4200/1020124 to your computer and use it in GitHub Desktop.
Save k4200/1020124 to your computer and use it in GitHub Desktop.
AkkaのサイトにあるFutureの例
// http://akka.io/docs/akka/1.1.2/scala/futures.html
// にあるサンプルコードの説明をコメントとして記入しました。
// 間違い等があれば指摘してもらえればと思います。
// 以下の2行はnon-blockingな処理
val f1 = actor1 !!! msg1 // actor1 に msg1 を投げ、Futureを得る
val f2 = actor2 !!! msg2 // actor2 に msg2 を投げ、Futureを得る
// この時点では actor1, actor2 の処理は終わっていない
// f3 は actor3 にメッセージを投げた結果のFuture
val f3 = for {
a: Int <- f1 // actor1 からの処理結果を a に入れる
b: Int <- f2 // actor2 からの処理結果を b に入れる
// actor1, actor2 の処理が終わった時点でactor3 に a+b を投げる
c: String <- actor3 !!! (a + b)
} yield c
val result = f3.get() // actor3 の処理が終わった時点で、result に結果が入る
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment