相关疑难解决方法(0)

kotlin coroutines,coroutineScope和withContext有什么区别

withContext
suspend fun <T> withContext(
    context: CoroutineContext, 
    block: suspend CoroutineScope.() -> T
): T (source)
Calls the specified suspending block with a given coroutine context, suspends until it completes, and returns the result.
Run Code Online (Sandbox Code Playgroud)
suspend fun <R> coroutineScope(
    block: suspend CoroutineScope.() -> R
): R (source)
Creates a CoroutineScope and calls the specified suspend block with this scope. The provided scope inherits its coroutineContext from the outer scope, but overrides the context’s Job.
Run Code Online (Sandbox Code Playgroud)

withContext采用CoroutineContext,并且似乎都complete在其所有子级完成之后。

在什么情况下,withContext或者coroutineScope应该比其他的首选? …

kotlin-coroutines coroutinescope withcontext

8
推荐指数
1
解决办法
395
查看次数