DEV Community

Discussion on: Go for Java developers (or is the Java concurrency that bad?!)

Collapse
 
netvl profile image
Vladimir Matveev

I think you can write the third function in an even shorter way with Future.traverse instead of Future.sequence:

Future.firstCompletedOf(Seq(
  Future.traverse(Future.firstCompletedOf)(Seq(
    Seq(web(query), webReplicated(query)),
    Seq(image(query), imageReplicated(query)),
    Seq(video(query), videoReplicated(query))
  )),
  failAfter(timeOut)
))

I didn't expect this, but I discovered that Future.traverse is really handy in lots of situations.