选择两个异步期货中的第一个来完成
Pick the first of two asynchronous futures to complete
是否有一个 scala 组合器可以按如下方式组合两个 futures
val Comb[A]: (Future[A], Future[A]) => Future[A] =
(f1: Future[A], f2: Future[A]) => Future {
if f1 succeeds before f2 then f1
else f2
}
同时在完成之前丢弃第二个未来?
Future.firstCompletedOf(...)
正是这样做的。
对于你正在尝试做的事情:
def Comb[A](f1: Future[A], f2: Future[A]): Future[A] =
Future.firstCompletedOf(Seq(f1, f2))
是否有一个 scala 组合器可以按如下方式组合两个 futures
val Comb[A]: (Future[A], Future[A]) => Future[A] =
(f1: Future[A], f2: Future[A]) => Future {
if f1 succeeds before f2 then f1
else f2
}
同时在完成之前丢弃第二个未来?
Future.firstCompletedOf(...)
正是这样做的。
对于你正在尝试做的事情:
def Comb[A](f1: Future[A], f2: Future[A]): Future[A] =
Future.firstCompletedOf(Seq(f1, f2))