Complete the code to pause the coroutine without blocking the thread.
suspend fun pause() {
[1](1000L)
}The delay function pauses the coroutine without blocking the thread, unlike Thread.sleep.
Complete the code to block the current thread for 500 milliseconds.
fun blockThread() {
[1](500)
}Thread.sleep blocks the current thread for the specified time.
Fix the error in the coroutine by replacing the blocking call with a suspending function.
suspend fun waitOneSecond() {
[1](1000L)
}In coroutines, delay should be used instead of Thread.sleep to avoid blocking the thread.
Fill both blanks to create a coroutine that prints before and after a non-blocking delay.
suspend fun printWithDelay() {
println("Start")
[1](2000L)
println([2])
}Use delay to suspend without blocking, then print "End" after the delay.
Fill all three blanks to create a coroutine that delays, then blocks the thread, and finally prints a message.
suspend fun mixedWait() {
[1](1000L)
[2](500)
println([3])
}The coroutine first suspends with delay, then blocks the thread with Thread.sleep, and finally prints "Finished".