Skip to content

Commit 110ca3d

Browse files
authored
Update docs about creating custom CoroutineScopes (#3306)
1 parent d737da6 commit 110ca3d

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

kotlinx-coroutines-core/common/src/CoroutineScope.kt

+6-6
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ import kotlin.coroutines.intrinsics.*
4242
* ### Custom usage
4343
*
4444
* `CoroutineScope` should be declared as a property on entities with a well-defined lifecycle that are
45-
* responsible for launching children coroutines. The corresponding instance of `CoroutineScope` shall be created
46-
* with either `CoroutineScope()` or `MainScope()` functions. The difference between them is only in the
47-
* [CoroutineDispatcher]:
45+
* responsible for launching child coroutines. The corresponding instance of `CoroutineScope` shall be created
46+
* with either `CoroutineScope()` or `MainScope()`:
4847
*
49-
* * `CoroutineScope()` uses [Dispatchers.Default] for its coroutines.
50-
* * `MainScope()` uses [Dispatchers.Main] for its coroutines.
48+
* * `CoroutineScope()` uses the [context][CoroutineContext] provided to it as a parameter for its coroutines
49+
* and adds a [Job] if one is not provided as part of the context.
50+
* * `MainScope()` uses [Dispatchers.Main] for its coroutines and has a [SupervisorJob].
5151
*
52-
* **The key part of custom usage of `CustomScope` is cancelling it at the end of the lifecycle.**
52+
* **The key part of custom usage of `CoroutineScope` is cancelling it at the end of the lifecycle.**
5353
* The [CoroutineScope.cancel] extension function shall be used when the entity that was launching coroutines
5454
* is no longer needed. It cancels all the coroutines that might still be running on behalf of it.
5555
*

0 commit comments

Comments
 (0)