Closed belamenso closed 5 months ago
Consider this piece of code in futures.scala:
ac.scheduler.execute: () => async: link() Async.group: complete(Try(body)) unlink()
and add print statements to it:
ac.scheduler.execute: () => println("-- 1") async: println("-- 2") link() println("-- 3") Async.group: println("-- 31") complete(Try(body)) println("-- 32") println("-- 4") unlink() println("-- 5")
Now run this code
given ExecutionContext = ExecutionContext.global val a = Future{ setName("a"); Thread.sleep(2000L); 22 } Async.blocking: println(a.value)
This will be the result:
-- 1 -- 2 -- 3 -- 31 22 Process finished with exit code 0
The same output is achieved if val a = Future{ setName("a"); Thread.sleep(2000L); 22 } is inside the Async.blocking block.
val a = Future{ setName("a"); Thread.sleep(2000L); 22 }
Async.blocking
Consider this piece of code in futures.scala:
and add print statements to it:
Now run this code
This will be the result:
The same output is achieved if
val a = Future{ setName("a"); Thread.sleep(2000L); 22 }
is inside theAsync.blocking
block.