Skip to content

Instantly share code, notes, and snippets.

@neogeogre
Created November 2, 2021 20:10
Show Gist options
  • Save neogeogre/129edc610de91ae5ca3cfcc589c09bd3 to your computer and use it in GitHub Desktop.
Save neogeogre/129edc610de91ae5ca3cfcc589c09bd3 to your computer and use it in GitHub Desktop.
wait the end of multiple coroutine
import kotlinx.coroutines.Dispatchers.Default
import kotlinx.coroutines.joinAll
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import mu.KotlinLogging
import java.lang.Thread.sleep
private val logger = KotlinLogging.logger {}
fun main() {
logger.info { "start" }
runBlocking {
val jobs = IntRange(0, 2).map {
launch(Default) {
logger.info { "launch $it" }
sleep(5000)
}
}
jobs.joinAll()
}
logger.info { "stop" }
}
// implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2-native-mt'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment