3 ms·
The issue is that this: val future1 = asyncService1() val future2 = asyncService2() val future3 = asyncService3() val future4 = asyncService4() val
by empirewindrush 12y ago
The issue is that this:
val future1 = asyncService1()
val future2 = asyncService2()
val future3 = asyncService3()
val future4 = asyncService4()
val resultFuture:Future = for { //For-comprehension
r1 <- future1
r2 <- future2
r3 <- future3
r4 <- future4
} yield (someOperation(r1, r2, r3, r4))
looks a lot like this
val resultFuture:Future = for { //For-comprehension
r1 <- asyncService1()
r2 <- asyncService2()
r3 <- asyncService3()
r4 <- asyncService4()
} yield (someOperation(r1, r2, r3, r4))
But the second one will be sequential. This is a common trap for new Scala futures users. You are right (as is the op below) that the first one work the way you expect. It is just easy for new users who don't understand how the de-sugaring resolves for get "caught."
- eklavya 12y agoYeah but that's my point they are doing it right.They are not falling into the trap ;)
- empirewindrush 12y agoYou are right. I jumped on it without giving the author the benefit of the doubt. This is one of those things that I personally have been burned by, and I wanted to save other from falling victim to the same mistake.