Re:Why we love Scala at Coursera
by NickPollard on Tuesday February 18, 2014 @02:13PM
(#7260322)
Scala derail: You might have an unintentional happens-before relationship in that example: The deletePersons call will end up being in the flatMap of the putAll[Person] call, which means it wont be started until the putAll finishes, when by the looks of it you could do both at once (only the createPerson needs to happen first).
You might want to do something like this:
for {
createResult <- Graph.createPerson(person)
} yield {
val a = Search.putAll[Person](createResult \ "updated_nodes")
val b = Search.deletePersons(createResult \ "deleted_nodes")
for ( _ <- a; _ <- b ) yield Created(createResult \ "node")
}
(notice starting the computations outside of the second for-comprehension, then just waiting for them inside)
You might want to do something like this:
(notice starting the computations outside of the second for-comprehension, then just waiting for them inside)