Skip to content

Instantly share code, notes, and snippets.

@MasoudFallahpour
Last active June 14, 2022 11:30
Show Gist options
  • Save MasoudFallahpour/3bb4fd22401de39a61c1d9c2089a33e9 to your computer and use it in GitHub Desktop.
Save MasoudFallahpour/3bb4fd22401de39a61c1d9c2089a33e9 to your computer and use it in GitHub Desktop.
import kotlinx.coroutines.CoroutineName
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
fun main() = runBlocking {
val request = launch(CoroutineName("request")) {
repeat(3) { i ->
launch {
delay((i + 1) * 200L) // variable delay 200ms, 400ms, 600ms
println("Coroutine $i is done")
}
}
println("request: I'm done")
}
request.join()
println("Processing of the request is complete")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment