Complete the code to launch a coroutine that prints "Hello".
import kotlinx.coroutines.* fun main() = runBlocking { [1] { println("Hello") } }
The launch builder starts a new coroutine without blocking the current thread.
Complete the code to launch a coroutine that delays for 1000ms before printing "Done".
import kotlinx.coroutines.* fun main() = runBlocking { launch { [1](1000) println("Done") } }
The delay function suspends the coroutine without blocking the thread.
Fix the error in the code to correctly launch a coroutine inside runBlocking.
import kotlinx.coroutines.* fun main() = runBlocking { [1] { println("Inside coroutine") } }
run which is not a coroutine builder.coroutineScope without proper context.The launch builder is the correct way to start a coroutine inside runBlocking.
Fill both blanks to launch a coroutine that prints the thread name.
import kotlinx.coroutines.* fun main() = runBlocking { [1] { println("Running on: " + Thread.[2]().name) } }
mainThread which does not exist.async when no result is needed.launch starts the coroutine, and Thread.currentThread gets the current thread.
Fill all three blanks to launch a coroutine that delays and then prints a message with the delay time.
import kotlinx.coroutines.* fun main() = runBlocking { val time = 500L [1] { [2](time) println("Waited for [3] ms") } }
async instead of launch when no result is needed.time in the print statement.launch starts the coroutine, delay suspends it, and time is the variable holding the delay duration.