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?
Asked
Active
Viewed 89 times
0

sof
- 9,113
- 16
- 57
- 83
1 Answers
2
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))

Community
- 1
- 1

Francis Toth
- 1,595
- 1
- 11
- 23