Skip to content

Commit

Permalink
Update docs about creating custom CoroutineScopes (#3306)
Browse files Browse the repository at this point in the history
  • Loading branch information
zsmb13 committed May 30, 2022
1 parent d737da6 commit 110ca3d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions kotlinx-coroutines-core/common/src/CoroutineScope.kt
Expand Up @@ -42,14 +42,14 @@ import kotlin.coroutines.intrinsics.*
* ### Custom usage
*
* `CoroutineScope` should be declared as a property on entities with a well-defined lifecycle that are
* responsible for launching children coroutines. The corresponding instance of `CoroutineScope` shall be created
* with either `CoroutineScope()` or `MainScope()` functions. The difference between them is only in the
* [CoroutineDispatcher]:
* responsible for launching child coroutines. The corresponding instance of `CoroutineScope` shall be created
* with either `CoroutineScope()` or `MainScope()`:
*
* * `CoroutineScope()` uses [Dispatchers.Default] for its coroutines.
* * `MainScope()` uses [Dispatchers.Main] for its coroutines.
* * `CoroutineScope()` uses the [context][CoroutineContext] provided to it as a parameter for its coroutines
* and adds a [Job] if one is not provided as part of the context.
* * `MainScope()` uses [Dispatchers.Main] for its coroutines and has a [SupervisorJob].
*
* **The key part of custom usage of `CustomScope` is cancelling it at the end of the lifecycle.**
* **The key part of custom usage of `CoroutineScope` is cancelling it at the end of the lifecycle.**
* The [CoroutineScope.cancel] extension function shall be used when the entity that was launching coroutines
* is no longer needed. It cancels all the coroutines that might still be running on behalf of it.
*
Expand Down

0 comments on commit 110ca3d

Please sign in to comment.