Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- object Timeout {
- def main(args: Array[String]): Unit = {
- runWithTimeout(10000) {
- val timeout = 1000 * 4
- println("Started the f")
- Thread.sleep(timeout)
- println(s"writing inside of the shit function ($timeout)")
- }
- println("End block")
- val task = () => println("Jesus??")
- println("Before")
- runWithTimeout(2200)(task) // this is never printed
- runWithTimeout(2200){ println("Jesus??") } // but this is
- }
- def runWithTimeout(timeout: Long)(f: => Unit): Unit = {
- Await.result(Future(f), timeout.milliseconds)
- println(s"writing outside of the function ($timeout)")
- }
- }
- // Started the f
- // writing inside of the shit function (4000)
- // writing outside of the function (10000)
- // End block
- // Before
- // writing outside of the function (2200)
- // Jesus??
- // writing outside of the function (2200)
- // QUESTION 1.
- // why line #13 did not produce output
- // QUESTION 2.
- // explain the difference between
- // val task = () => println("Jesus??")
- // vs
- // val task = { println("Jesus??") }
- // Thank you
Add Comment
Please, Sign In to add comment