Reputation: 9649
There are futures f1, f2 and f3. If we need wait till both f1 and
f2 complete or
f3 does, i.e. the condition looks like completed(f1) & completed(f2) | completed(f3)
, how can we use Scala Async to compose it fluently?
Upvotes: 0
Views: 91
Reputation: 1685
I don't know async, but you could probably find a solution using Future.firstCompletedOf and promises. There's already a post on SO about this.
If you don't care about cancelling the futures, you can simply do something like :
val f1 = Future { /*...*/ }
val f2 = Future { /*...*/ }
val f3 = Future { /*...*/ }
Future.firstCompletedOf(Seq(f1.flatMap(f2), f3))
Upvotes: 2