Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- object Tmp extends App {
- val f = Future {
- val r = Random.nextInt(500)
- if (r < 499)
- throw new RuntimeException("bad value")
- r
- }
- f.onComplete(ff => {
- if (ff.isSuccess) {
- println(s"success ${ff.get}")
- }
- })
- f.failed.foreach(t => s"failure ${t.getMessage}")
- // do the rest of your work
- println("A ..."); Thread.sleep(100)
- println("B ..."); Thread.sleep(100)
- println("C ..."); Thread.sleep(100)
- println("D ..."); Thread.sleep(100)
- println("E ..."); Thread.sleep(100)
- println("F ..."); Thread.sleep(100)
- Thread.sleep(1000)
- }
- A ...
- B ...
- C ...
- D ...
- E ...
- F ...
Add Comment
Please, Sign In to add comment