Complete the code to launch a coroutine in the Main scope.
GlobalScope.[1] { println("Hello from coroutine") }
The launch builder starts a new coroutine without blocking the current thread.
Complete the code to start an async coroutine that returns a value.
val deferred = GlobalScope.[1] { delay(1000) return@[1] 42 }
The async builder starts a coroutine and returns a Deferred which holds a future result.
Fix the error in the code by choosing the correct coroutine builder.
val result = GlobalScope.[1] { delay(500) 10 + 20 } println(result.await())
Only async returns a Deferred that supports await() to get the result.
Fill both blanks to create a coroutine that launches and then waits for an async result.
GlobalScope.[1] { val deferred = async { delay(300) 5 * 5 } val result = deferred.[2]() println(result) }
Use launch to start the coroutine and await to get the async result.
Fill all three blanks to create an async coroutine that returns a computed value after delay.
val deferred = GlobalScope.[1] { delay(200) val x = 10 val y = 20 x [2] y } println(deferred.[3]())
Use async to start coroutine returning a value, + to add, and await to get the result.