请教一个问题

来源:12-11 案例:仿官方框架实现作用域2

慕前端9039556

2022-07-15

Creates a [CoroutineScope] with [SupervisorJob] and calls the specified suspend block with this scope.
The provided scope inherits its [coroutineContext][CoroutineScope.coroutineContext] from the outer scope, but overrides context’s [Job] with [SupervisorJob].

使用 [SupervisorJob] 创建一个 [CoroutineScope] 并使用此范围调用指定的挂起块。
提供的范围从外部范围继承其 [coroutineContext][CoroutineScope.coroutineContext],但用 [SupervisorJob] 覆盖上下文的 [Job]。

这是 supervisorScope 函数的官方注释。我并没有发现在哪里使用 [SupervisorJob] 覆盖 [父Job]这个行为。
我又检查了您实现的 简易协程框架中的 supervisorScope ,仍然没有发现利用 [SupervisorJob] 覆盖 [父Job]这个行为。仅仅是 创建一个 SupervisorCoroutine 实例,并开启协程。

写回答

1回答

bennyhuo

2022-07-15

SupervisorCoroutine 就是一个 Job。
0
0

学会Kotlin 突破开发语言瓶颈

如果有一门语言可以取代Java,那么它一定是Kotlin。

1760 学习 · 481 问题

查看课程