Created
October 30, 2012 14:01
-
-
Save arturaz/3980328 to your computer and use it in GitHub Desktop.
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
private[this] def picker[Question, Yes, No, Value]( | |
question: Question, onSuccess: Yes => Left[Value, Unit] | |
)( | |
implicit mYes: Manifest[Yes], mNo: Manifest[No] | |
): Future[Either[Value, Unit]] = { | |
// Promise for fallbacking that we're never going to fulfill. | |
val unfulfilledPromise = Promise() | |
val questions = actors.map { actor => actor ? question } | |
val successQuestions = questions.map { | |
_ mapTo mYes map onSuccess fallbackTo(unfulfilledPromise) | |
} | |
val success= Future.firstCompletedOf(successQuestions) | |
val failureQuestions = questions.map { _ mapTo mNo } | |
val failure = Future.sequence(failureQuestions) map { _ => Right() } | |
Future.firstCompletedOf(Seq(success, failure)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment