Created
December 12, 2011 09:20
-
-
Save gre/1466144 to your computer and use it in GitHub Desktop.
Play20 Promise sequence function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
fixed https://gist.github.com/1466196 :)