Complete the code to declare a suspend function named fetchData.
suspend fun [1]() {
// simulate fetching data
}The function name must be fetchData as requested.
Complete the code to call the suspend function fetchData inside a coroutine scope.
import kotlinx.coroutines.* fun main() = runBlocking { [1]() }
You need to call the suspend function fetchData() inside runBlocking.
Fix the error in the suspend function declaration by filling the blank.
fun [1] fetchData() {
// code
}The keyword suspend is required before the function name to declare a suspend function.
Fill both blanks to create a suspend function that delays for 1000 milliseconds and then prints a message.
suspend fun waitAndPrint() {
[1](1000L)
println([2])
}The delay function pauses the coroutine, and then the message "Done waiting!" is printed.
Fill all three blanks to create a suspend function that fetches data, delays, and returns a string result.
suspend fun fetchData(): String {
val data = "Data"
[1](500L)
return [2] + [3]
}The function delays for 500 milliseconds, then returns the string data + " fetched".