Created
August 13, 2021 05:05
-
-
Save noseratio/636202e1bbf4ca66f516e7253231a045 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.coroutines.* | |
suspend fun suspendableDelay(ms: Long): Long { | |
delay(ms); | |
return ms; | |
} | |
fun regularDelay(ms: Long): Deferred<Long> { | |
val d = CompletableDeferred<Long>() | |
GlobalScope.async { delay(ms); d.complete(ms) } | |
return d; | |
} | |
suspend fun test(ms: Long): Long { | |
delay(ms); | |
return ms; | |
} | |
fun main() { | |
val r1 = runBlocking { suspendableDelay(250) } | |
println("suspendableDelay ended: $r1"); | |
val r2 = runBlocking { regularDelay(500).await() } | |
println("regularDelay ended: $r2"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment