斯卡拉等待期货顺序
发布时间:2020-12-16 09:14:31 所属栏目:安全 来源:网络整理
导读:我希望如下的代码将等待两个期货,但不会. object Fiddle { val f1 = Future { throw new Throwable("baaa") // emulating a future that bumped into an exception } val f2 = Future { Thread.sleep(3000L) // emulating a future that takes a bit longer
我希望如下的代码将等待两个期货,但不会.
object Fiddle { val f1 = Future { throw new Throwable("baaa") // emulating a future that bumped into an exception } val f2 = Future { Thread.sleep(3000L) // emulating a future that takes a bit longer to complete 2 } val lf = List(f1,f2) // in the general case,this would be a dynamically sized list val seq = Future.sequence(lf) seq.onComplete { _ => lf.foreach(f => println(f.isCompleted)) } } val a = FuturesSequence 我假设seq.onComplete将等待他们完成之前完成自己,但不是这样;它导致: true false 顺序在scala.concurrent.Future的源头上有点难以追随,我不知道我将如何实现一个等待所有原始期货(动态大小)序列的并行,或者这里可能是什么问题. 编辑:相关问题:https://worldbuilding.stackexchange.com/questions/12348/how-do-you-prove-youre-from-the-future (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容