Guest User

Untitled

a guest
Dec 15th, 2018
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. object Timeout {
  2. def main(args: Array[String]): Unit = {
  3. runWithTimeout(10000) {
  4. val timeout = 1000 * 4
  5. println("Started the f")
  6. Thread.sleep(timeout)
  7. println(s"writing inside of the shit function ($timeout)")
  8. }
  9. println("End block")
  10.  
  11. val task = () => println("Jesus??")
  12. println("Before")
  13. runWithTimeout(2200)(task) // this is never printed
  14. runWithTimeout(2200){ println("Jesus??") } // but this is
  15. }
  16.  
  17. def runWithTimeout(timeout: Long)(f: => Unit): Unit = {
  18. Await.result(Future(f), timeout.milliseconds)
  19. println(s"writing outside of the function ($timeout)")
  20. }
  21. }
  22.  
  23. // Started the f
  24. // writing inside of the shit function (4000)
  25. // writing outside of the function (10000)
  26. // End block
  27. // Before
  28. // writing outside of the function (2200)
  29. // Jesus??
  30. // writing outside of the function (2200)
  31.  
  32.  
  33. // QUESTION 1.
  34. // why line #13 did not produce output
  35.  
  36. // QUESTION 2.
  37. // explain the difference between
  38. // val task = () => println("Jesus??")
  39. // vs
  40. // val task = { println("Jesus??") }
  41.  
  42. // Thank you
Add Comment
Please, Sign In to add comment