File tree Expand file tree Collapse file tree 4 files changed +13
-13
lines changed Expand file tree Collapse file tree 4 files changed +13
-13
lines changed Original file line number Diff line number Diff line change @@ -428,13 +428,13 @@ Future は同じ `Throwable` とともに失敗する。
428428ソーシャルネットワークからの最近の投稿文を可変セットに保存して、全ての投稿文を画面に表示する以下の具体例をみてみよう:
429429
430430 val allposts = mutable.Set[String]()
431-
431+
432432 Future {
433433 session.getRecentPosts
434434 } andThen {
435- posts => allposts ++= posts
435+ case Success( posts) => allposts ++= posts
436436 } andThen {
437- posts =>
437+ case _ =>
438438 clearAll()
439439 for (post <- allposts) render(post)
440440 }
Original file line number Diff line number Diff line change @@ -699,13 +699,13 @@ which stores the recent posts from a social network to a mutable set
699699and then renders all the posts to the screen:
700700
701701 val allposts = mutable.Set[String]()
702-
702+
703703 Future {
704704 session.getRecentPosts
705705 } andThen {
706- posts => allposts ++= posts
706+ case Success( posts) => allposts ++= posts
707707 } andThen {
708- posts =>
708+ case _ =>
709709 clearAll()
710710 for (post <- allposts) render(post)
711711 }
Original file line number Diff line number Diff line change @@ -386,13 +386,13 @@ which stores the recent posts from a social network to a mutable set
386386and then renders all the posts to the screen:
387387
388388 val allposts = mutable.Set[String]()
389-
389+
390390 Future {
391391 session.getRecentPosts
392392 } andThen {
393- posts => allposts ++= posts
393+ case Success( posts) => allposts ++= posts
394394 } andThen {
395- posts =>
395+ case _ =>
396396 clearAll()
397397 for (post <- allposts) render(post)
398398 }
Original file line number Diff line number Diff line change @@ -299,13 +299,13 @@ fallbackTo组合器生成的future对象可以在该原future成功完成计算
299299组合器andThen的用法是出于纯粹的side-effecting目的。经andThen返回的新Future无论原Future成功或失败都会返回与原Future一模一样的结果。一旦原Future完成并返回结果,andThen后跟的代码块就会被调用,且新Future将返回与原Future一样的结果,这确保了多个andThen调用的顺序执行。正如下例所示,这段代码可以从社交网站上把近期发出的帖子收集到一个可变集合里,然后把它们都打印在屏幕上:
300300
301301 val allposts = mutable.Set[String]()
302-
303- future {
302+
303+ Future {
304304 session.getRecentPosts
305305 } andThen {
306- posts => allposts ++= posts
306+ case Success( posts) => allposts ++= posts
307307 } andThen {
308- posts =>
308+ case _ =>
309309 clearAll()
310310 for (post <- allposts) render(post)
311311 }
You can’t perform that action at this time.
0 commit comments