Created
November 2, 2021 20:10
-
-
Save neogeogre/129edc610de91ae5ca3cfcc589c09bd3 to your computer and use it in GitHub Desktop.
wait the end of multiple coroutine
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.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