Skip to content

Conversation

@zsmb13
Copy link
Contributor

@zsmb13 zsmb13 commented May 30, 2022

Clarify the difference between MainScope() and CoroutineScope(), remove mention of CustomScope

@qwwdfsad qwwdfsad self-requested a review May 30, 2022 09:37
@qwwdfsad qwwdfsad changed the base branch from master to develop May 30, 2022 09:37
Copy link
Member

@qwwdfsad qwwdfsad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@qwwdfsad qwwdfsad merged commit 110ca3d into Kotlin:develop May 30, 2022
* * `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.
Copy link
Collaborator

@dkhalanskyjb dkhalanskyjb May 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The part about Dispatchers.Default is important though. If one knows that Dispatchers.Default is used by default, yes, it's obvious what happens when a dispatcher is not specified, but if one does not, it's unclear where to look.

Copy link
Member

@qwwdfsad qwwdfsad May 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every coroutine builder mentions Dispatchers.Default though:

If the context does not have any dispatcher or other [ContinuationInterceptor], then [Dispatchers.Default] is used.
The parent job is inherited from the [CoroutineScope] as well, but it can also be overridden
with a corresponding [context] element.

And mentioning Dispatchers.Default here is just being incorrect -- CoroutineScope() does not provide any dispatcher and each coroutine decides what to use on its own. E.g. some may use Dispatches.Unconfined when the dispatcher is not supplied

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok, didn't notice launch mentioning Dispatchers.Default.

pablobaxter pushed a commit to pablobaxter/kotlinx.coroutines that referenced this pull request Sep 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants