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

flowOn(Dispatchers.Main) does not change upstream dispatcher #3545

Closed
hoc081098 opened this issue Dec 2, 2022 · 1 comment
Closed

flowOn(Dispatchers.Main) does not change upstream dispatcher #3545

hoc081098 opened this issue Dec 2, 2022 · 1 comment
Assignees
Labels

Comments

@hoc081098
Copy link

    flowOf(1)
      .onEach {
        Timber.d("timer: $it ${Thread.currentThread().name} ${currentCoroutineContext()[ContinuationInterceptor]}")
      }
      .flowOn(Dispatchers.Main)
      .onEach {
        Timber.d("timer [1]: $it ${Thread.currentThread().name} ${currentCoroutineContext()[ContinuationInterceptor]}")
      }
      .launchIn(viewModelScope)

// viewModelScope's context is SupervisorJob() + Dispatchers.Main.immediate

Console

timer: 1 main Dispatchers.Main.immediate
timer [1]: 1 main Dispatchers.Main.immediate
@hoc081098
Copy link
Author

hoc081098 commented Dec 2, 2022

I saw Dispatchers.Main == Dispatchers.Main.immediate gives true (because they have the same Handler,

override fun equals(other: Any?): Boolean = other is HandlerContext && other.handler === handler
)

So


will not change the context.

Is that expected behavior?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants