Complete the code to launch a coroutine that prints "Hello".
GlobalScope.[1] { println("Hello") }
runBlocking inside GlobalScope.launch which blocks the thread.delay as a coroutine builder which is incorrect.The launch function starts a new coroutine without blocking the current thread.
Complete the code to block the main thread until the coroutine finishes.
runBlocking [1] { launch { println("Running in coroutine") } }
async as a parameter to runBlocking.The runBlocking function takes a lambda block enclosed in curly braces { } to run coroutine code and block the thread.
Fix the error in the code to correctly start a thread that prints "Thread running".
val thread = Thread [1] { println("Thread running") } thread.start()
The Thread constructor takes a lambda block enclosed in curly braces { } to define the thread's work.
Fill both blanks to create a coroutine that delays for 1000ms and then prints "Done".
GlobalScope.[1] { delay([2]) println("Done") }
runBlocking instead of launch.500 instead of 1000L for delay.The launch builder starts the coroutine, and delay(1000L) pauses it for 1000 milliseconds.
Fill all three blanks to create a map of coroutine names to their status checking if they are active.
val coroutinesStatus = mapOf(
"coroutine1" to [1],
"coroutine2" to [2],
"coroutine3" to [3]
)Each coroutine job has an isActive property to check if it is still running.