Skip to content

consider exposing the Executor from a CoroutineDispatcher. #385

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
hsyed opened this issue Jun 6, 2018 · 4 comments
Closed

consider exposing the Executor from a CoroutineDispatcher. #385

hsyed opened this issue Jun 6, 2018 · 4 comments

Comments

@hsyed
Copy link

hsyed commented Jun 6, 2018

In various contexts (--e.g., dagger2 producers, various guava async utils) the Executor could be the same as the coroutine dispatcher. Could we get access to the executor so that we can use it directly at least on CommonPool and user created ThreadPoolDispatcher. Having to inject both or provide both is annoying.

@qwwdfsad
Copy link
Member

qwwdfsad commented Jun 9, 2018

Why executor.asCoroutineDispatcher() is not applicable for this purpose?

@hsyed
Copy link
Author

hsyed commented Jun 28, 2018

Sorry for the delay. That is going from executor to dispatcher. I think going from dispatcher (CommonPool, ThreadPoolDispatcher) back should be possible as well.

Its quite common to be in a coroutine and have to interact with something expecting an executor and that the executor should be the same pool. If the graph is wired up through di you would have to bind an underlying executor as well as a dispatcher.

If you only bind and executor and go from to executor to dispatcher thats extra allocation each time no ?

@qwwdfsad
Copy link
Member

qwwdfsad commented Jun 29, 2018

Hi @hsyed
In general, going back is not always possible.
E.g. in CommonPool underlying pool will be soon replaced by our own hand-rolled thread pool which may be not an instance of Executor.

One of the solutions is to provide access to the underlying executor for executor-based dispatchers (asCoroutineDispatcher, newFixedThreadPoolContext, newSingleThreadContext).
But going from executor to dispatcher will always cost you an allocation if you have only an executor. Will it be enough?

@hsyed
Copy link
Author

hsyed commented Jun 29, 2018

@qwwdfsad Yes that is what I was thinking of.

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