Skip to content

Introduce API to inject main dispatcher #746

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

Closed
qwwdfsad opened this issue Oct 22, 2018 · 3 comments
Closed

Introduce API to inject main dispatcher #746

qwwdfsad opened this issue Oct 22, 2018 · 3 comments
Assignees
Milestone

Comments

@qwwdfsad
Copy link
Collaborator

qwwdfsad commented Oct 22, 2018

Otherwise, Android users should inject main dispatcher into their classes to use Unconfined in tests. This is pretty ugly, especially when Dispatchers.Main is already here.

Proposed solution:
Introduce module kotlinx-coroutines-core-test which overrides Main dispatcher and API to inject any dispatcher as Main.

So users can use launch(Dispatchers.Main) and in tests all they need is to add a dependency to kotlinx-coroutines-core-test and use MainDispatcherInjector.inject(dispatcher: CoroutineDispatcher).

@qwwdfsad qwwdfsad self-assigned this Oct 22, 2018
@qwwdfsad qwwdfsad changed the title Introduce way to inject main dispatcher Introduce API to inject main dispatcher Oct 22, 2018
@pull-vert
Copy link

I think providing a separate module 'kotlinx-coroutines-core-test'' is really important, to provide Coroutines users a dedicated module with some useful testing tools such as TestBase or TestCoroutineContext (this last one provides useful delay testing features, but will need some changes, also it shouldn't be in 'kotlinx-coroutines-core').

@qwwdfsad
Copy link
Collaborator Author

Yes, that's the plan. The plan is to provide more testing utilities (sequential execution validation, virtual time, debug capabilities etc.)

@qwwdfsad qwwdfsad added this to the Release 1.1 milestone Oct 26, 2018
@BoxResin
Copy link

This feature is really needed!

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

No branches or pull requests

3 participants