https://kotlinlang.org logo
#coroutines
Title
# coroutines
h

halim

08/01/2019, 2:34 PM
hi
Copy code
runBlocking {
      println("start main")
      execute(coroutineContext) {  println("some long operation")  }
      println("main done")
}

fun execute(context: CorouitneContext, action: suspend () -> Unit) {
      action.startCorouitne(Continuation(context + <http://Dispatchers.IO|Dispatchers.IO>) {
            println("corouitne complete")
     })
}
so when execute : start main main done, i expected to see : corouitne complete "startCorouitne" start a new coroutine in my case i bound it to runBlocking scope (with context as parent) and with dispather IO, so i expect to see "coroutine complete" in console ?? i think this new coroutne created by startCoroutine its not bound to runBlocking so when main is finish its ignore this corouitne
l

louiscad

08/01/2019, 2:53 PM
You should not use
startCoroutine
if you use kotlinx.coroutines. Consider using
withContext
or
launch
instead, if needed.