Coroutines are computer program components that generalize subroutines for non-preemptive multitasking,by allowing execution to be suspended and resumed. Coroutines are well-suited for implementing familiar program components such as cooperative tasks, exceptions, event loops, iterators, infinite lists and ...
*/ public val coroutineContext: CoroutineContext } CoroutineContext : Persistent context for the coroutine 代码语言:javascript 代码运行次数:0 运行 AI代码解释 package kotlin.coroutines /** * Persistent context for the coroutine. It is an indexed set of [Element] instances. * An indexed set is ...
构造CoroutineScope使用到的CoroutineContext是一个特殊的集合,这个集合它既有Map的特点,也有Set的特点,集合的每一个元素都是Element,每个Element都有一个Key与之对应,对于相同Key的Element是不可以重复存在的,Element之间可以通过+号组合起来,后面我会详细介绍CoroutineContext这个特殊集合的结构,接下来我先简单讲解一下组...
CommonPool 有点类似于 RxJava 的 Schedulers.computation(),主要是用于CPU密集型的计算任务。 CommonPool 使用 pool 来执行 block。 override fun dispatch(context: CoroutineContext, block: Runnable) =try { (pool ?: getOrCreatePoolSync()).execute(timeSource.trackTask(block)) }catch (e: RejectedExecu...
package kotlin.coroutines /** * Persistent context for the coroutine. It is an indexed set of [Element] instances. * An indexed set is a mix between a set and a map. * Every element in this set has a unique [Key]. */ @SinceKotlin("1.3") ...
前面我们讲到CoroutineDispatcher它本身也继承自ContinuationInterceptor,ContinuationInterceptor有一个interceptContinuation方法用于返回拦截协程的行为,而这个行为就是前面我们所讲到Dispatchers.Unconfined时的DispatchedContinuation,DispatchedContinuation在恢复协程前根据协程的CoroutineDispatcher类型做出不同的协程分派行为,通过把...
*/publicval context:CoroutineContext/** * Resumes the execution of the corresponding coroutine passing a successful or failed [result] as the * return value of the last suspension point. */publicfunresumeWith(result:Result<T>)} context是协程的上下文,它更多时候是CombinedContext类型,类似于协程的集...
假定你对协程(Coroutine)一点儿都不了解。 通过阅读本文看看是否能让你明白协程是怎么一回事。 1. 引子 我之前写过一些协程的文章,很久以前了。那会儿还是很痛苦的,毕竟kotlinx.coroutines这样强大的框架还在襁褓当中,于是乎我写的几篇协程的文章几乎就是在告诉大家如何写这样一个框架——那种感觉简直糟糕透了,因为...
public val context: CoroutineContext /** * Resumes the execution of the corresponding coroutine passing a successful or failed [result] as the * return value of the last suspension point. */ public fun resumeWith(result: Result<T>)
CommonPool 有点类似于 RxJava 的 Schedulers.computation(),主要是用于CPU密集型的计算任务。 CommonPool 使用 pool 来执行 block。 overridefun dispatch(context:CoroutineContext,block:Runnable)=try{(pool?:getOrCreatePoolSync()).execute(timeSource.trackTask(block))}catch(e:RejectedExecutionException){time...