Guest User

Untitled

a guest
Oct 22nd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. object Tmp extends App {
  2.  
  3. val f = Future {
  4. val r = Random.nextInt(500)
  5. if (r < 499)
  6. throw new RuntimeException("bad value")
  7. r
  8. }
  9. f.onComplete(ff => {
  10. if (ff.isSuccess) {
  11. println(s"success ${ff.get}")
  12. }
  13. })
  14. f.failed.foreach(t => s"failure ${t.getMessage}")
  15. // do the rest of your work
  16. println("A ..."); Thread.sleep(100)
  17. println("B ..."); Thread.sleep(100)
  18. println("C ..."); Thread.sleep(100)
  19. println("D ..."); Thread.sleep(100)
  20. println("E ..."); Thread.sleep(100)
  21. println("F ..."); Thread.sleep(100)
  22. Thread.sleep(1000)
  23. }
  24.  
  25. A ...
  26. B ...
  27. C ...
  28. D ...
  29. E ...
  30. F ...
Add Comment
Please, Sign In to add comment