Last active
December 11, 2015 23:48
-
-
Save theodoreLee/4679031 to your computer and use it in GitHub Desktop.
Play Future 처리 예제
This file contains 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
def bbb:Future[List[String]] = future { List("hi","there") } | |
def failedFuture:[List[String]] = future{ throw new RuntimeException("~~") } // or Future.failed(throw new ~~()) | |
def action1 = Action { | |
Async{ | |
bbb map { | |
list => //list:List[String] | |
Ok(list.mkString("~ ")) | |
} | |
} | |
} | |
def action2 = Action { | |
Async { | |
{ | |
for { | |
list <- bbb // list:List[String] <- bbb:Future[List[String]] | |
test <- failed //It will be failed | |
} yield { | |
Ok("It doesn't run") | |
} | |
} recover {//퓨쳐가 실패하면 여기서 에러(중 일부 또는 전부. 여기서는 전부)를 성공으로 봐꿔서 전달. | |
case e:Throwable => BadRequest(e.getMessage) //이 예제에서는 BadRequest가 나감. | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment