Created
February 18, 2016 16:38
-
-
Save nikolaybotev/097935aadeea0465a038 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
#!scala | |
import scala.concurrent.ExecutionContext.Implicits.global | |
import scala.util.Success | |
import scala.util.Failure | |
val x: Future[Boolean] = Future.successful(true) | |
val y: Future[Boolean] = Future.successful(false) | |
val xMapped: Future[Int] = x.map(_ match { case true => 42 case false => throw new Exception("hey") }) | |
xMapped onComplete { case Success(n) => println(s"Success $n") case Failure(e) => println(s"Failure ${e}") } | |
val yMapped: Future[Int] = y.map(_ match { case true => 42 case false => throw new Exception("hey") }) | |
yMapped onComplete { case Success(n) => println(s"Success $n") case Failure(e) => println(s"Failure ${e}") } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
showcase how scala Futures integrate with Exceptions