Search code examples
scalaparallel-processingactor

What is the benefit of using Futures over parallel collections in scala?


Is there a good reason for the added complexity of Futures (vs parallel collections) when processing a list of items in parallel?

List(...).par.foreach(x=>longRunningAction(x))  

vs

Future.traverse(List(...)) (x=>Future(longRunningAction(x)))

Solution

  • I think the main advantage would be that you can access the results of each future as soon as it is computed, while you would have to wait for the whole computation to be done with a parallel collection. A disadvantage might be that you end up creating lots of futures. If you later end up calling Future.sequence, there really is no advantage.