this is when I use the delay function
@Test
fun testJob(){
runBlocking {
val job = GlobalScope.launch {
println("Start Coroutine ${Date()}")
delay(1000)
println("End Coroutine ${Date()}")
}
job.cancel()
delay(2000)
}
}
this is when i use the Thread.sleep function
@Test
fun testJob(){
runBlocking {
val job = GlobalScope.launch {
println("Start Coroutine ${Date()}")
Thread.sleep(1000)
println("End Coroutine ${Date()}")
}
job.cancel()
delay(2000)
}
}
why cancel() can't work when i use Thread.sleep ?