News for hackers. Stuff that matters.

empirewindrush

Re:Microsoft is killing the Nokia and Windows Phone brands on Wednesday September 10, 2014 @04:09PM (#8298790)
Hey now, Cortana is a really cool use of a property they had access to. One of the perks of being a huge, diverse (in the product / market sense) company.
Re:Maximize Server Throughput with Scala Futures on Wednesday September 10, 2014 @02:34PM (#8298180)
You 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.
Re:Maximize Server Throughput with Scala Futures on Wednesday September 10, 2014 @02:25PM (#8298115)
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."
Re:Maximize Server Throughput with Scala Futures on Wednesday September 10, 2014 @02:19PM (#8298067)
Cool. Like I mentioned this is still better than the before case. This is a super confusing area of Futures for most people, especially the newer Scala users. I got burnt a couple of times by this. It might not be obvious how creating the future outside of the comprehension changes the behavior the someone new to the topic. This is one of those gotchas that can make Scala frustrating for new users.
Re:Maximize Server Throughput with Scala Futures on Wednesday September 10, 2014 @02:05PM (#8297980)
This is wrong. Well not wrong but it doesn't work the way it seems the author thinks it does. For comprehensions de-sugar in a way that isn't really great. See the first answer here. http://stackoverflow.com/questions/19045936/scalas-for-compr... .

Basically what he means with that code is: Do four things in parallel and then return the result. What his code ACTUALLY does is do 4 things in sequence in a non-blocking way. This isn't bad (certainly better than blocking for each step) but it misses the real value. He should fire the for futures and then use traverse or Future.sequence to combine them. It is uglier but actually achieves the intended result.