File tree 4 files changed +13
-13
lines changed
4 files changed +13
-13
lines changed Original file line number Diff line number Diff line change @@ -428,13 +428,13 @@ Future は同じ `Throwable` とともに失敗する。
428
428
ソーシャルネットワークからの最近の投稿文を可変セットに保存して、全ての投稿文を画面に表示する以下の具体例をみてみよう:
429
429
430
430
val allposts = mutable.Set[String]()
431
-
431
+
432
432
Future {
433
433
session.getRecentPosts
434
434
} andThen {
435
- posts => allposts ++= posts
435
+ case Success( posts) => allposts ++= posts
436
436
} andThen {
437
- posts =>
437
+ case _ =>
438
438
clearAll()
439
439
for (post <- allposts) render(post)
440
440
}
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
699
699
and then renders all the posts to the screen:
700
700
701
701
val allposts = mutable.Set[String]()
702
-
702
+
703
703
Future {
704
704
session.getRecentPosts
705
705
} andThen {
706
- posts => allposts ++= posts
706
+ case Success( posts) => allposts ++= posts
707
707
} andThen {
708
- posts =>
708
+ case _ =>
709
709
clearAll()
710
710
for (post <- allposts) render(post)
711
711
}
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
386
386
and then renders all the posts to the screen:
387
387
388
388
val allposts = mutable.Set[String]()
389
-
389
+
390
390
Future {
391
391
session.getRecentPosts
392
392
} andThen {
393
- posts => allposts ++= posts
393
+ case Success( posts) => allposts ++= posts
394
394
} andThen {
395
- posts =>
395
+ case _ =>
396
396
clearAll()
397
397
for (post <- allposts) render(post)
398
398
}
Original file line number Diff line number Diff line change @@ -299,13 +299,13 @@ fallbackTo组合器生成的future对象可以在该原future成功完成计算
299
299
组合器andThen的用法是出于纯粹的side-effecting目的。经andThen返回的新Future无论原Future成功或失败都会返回与原Future一模一样的结果。一旦原Future完成并返回结果,andThen后跟的代码块就会被调用,且新Future将返回与原Future一样的结果,这确保了多个andThen调用的顺序执行。正如下例所示,这段代码可以从社交网站上把近期发出的帖子收集到一个可变集合里,然后把它们都打印在屏幕上:
300
300
301
301
val allposts = mutable.Set[String]()
302
-
303
- future {
302
+
303
+ Future {
304
304
session.getRecentPosts
305
305
} andThen {
306
- posts => allposts ++= posts
306
+ case Success( posts) => allposts ++= posts
307
307
} andThen {
308
- posts =>
308
+ case _ =>
309
309
clearAll()
310
310
for (post <- allposts) render(post)
311
311
}
You can’t perform that action at this time.
0 commit comments