Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update docs about creating custom CoroutineScopes #3306

Merged
merged 1 commit into from May 30, 2022

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

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.

None yet

3 participants