Skip to content

Instantly share code, notes, and snippets.

@gre
Created December 12, 2011 09:20
Show Gist options
  • Save gre/1466144 to your computer and use it in GitHub Desktop.
Save gre/1466144 to your computer and use it in GitHub Desktop.
Play20 Promise sequence function
// What is a Promise sequence function ?
// A function which transform a List[Promise[A]] into a Promise[List[A]]
// First naive implementation. It's a synchronous implementation (blocking).
def sequencePromises[A](list: List[Promise[A]]): Promise[List[A]] = {
Promise.pure(
list.flatMap(e => e.value match {
case Redeemed(value) => Some(value)
case Thrown(e) => { Logger.debug("thrown "+e); None }
})
)
}
// non blocking implementation?
@gre
Copy link
Author

gre commented Dec 12, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment