Skip to content

Conversation

@seyoungcho2
Copy link
Contributor

In this part, it says that it checks whether it's the same coroutine, but in the actual implementation, it checks whether it's the same CoroutineContext rather than the same coroutine.

Specifically, in the case of the withContext example, although it internally creates a DispatchedCoroutine object, this is only for context switching, and it still maintains the same coroutine.

val myFlow = flow {
     // GlobalScope.launch { // is prohibited
     // launch(Dispatchers.IO) { // is prohibited
     // withContext(CoroutineName("myFlow")) { // is prohibited
     emit(1) // OK
     coroutineScope {
         emit(2) // OK -- still the same coroutine
     }
 }

Therefore, it might be less confusing to describe this as checking for the same coroutine context rather than the same coroutine.

(cherry picked from commit 755347c)
@seyoungcho2 seyoungcho2 changed the title Fix an explanation of flow emit Fix the explanation of flow emit constraints Mar 23, 2025
@dkhalanskyjb dkhalanskyjb merged commit 8627cc3 into Kotlin:develop Mar 24, 2025
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.

2 participants