티스토리 뷰

공부

[kotlin] wait for coroutine finish

승가비 2023. 2. 26. 11:42
728x90
suspend fun main() {
  val job = GlobalScope.launch { hello() }
  job.join()
  print("done")
}
fun main() = runBlocking {
  val job = launch { hello() }      
  job.join()
  print("done")
}

https://stackoverflow.com/questions/55904099/how-to-wait-for-all-coroutines-to-finish

 

How to wait for all coroutines to finish?

I'm launching a coroutine and I want it to finish before I resume execution of main thread. My code simplified looks like this: fun hello() { for (i in 0..100) { println("hello") ...

stackoverflow.com

 

728x90

'공부' 카테고리의 다른 글

[kotlin] semaphore & coroutine  (0) 2023.02.26
[spark] sql MONTHS_BETWEEN(a, b) -> a - b  (0) 2023.02.26
[kotlin] toSortedMap (key based)  (0) 2023.02.26
[scala] loop & data = data ++ data  (0) 2023.02.23
[kotlin] repeat(n) { ... }  (0) 2023.02.23
댓글