-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Support for blocking calls inside coroutines (#79) #83
Conversation
7ca7ffc
to
f5acb73
Compare
f5acb73
to
e9e6613
Compare
0b13569
to
35d2c34
Compare
e9e6613
to
9fccedc
Compare
start: CoroutineStart = CoroutineStart.DEFAULT, | ||
block: () -> T): Deferred<T> { | ||
require(start != CoroutineStart.UNDISPATCHED) { "Start blocking code undispatched is not supported" } | ||
return async(executor.asCoroutineDispatcher(), start) { block() } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should cache dispatcher created from DefaultBlockingExecutor to avoid dispatcher creation on each call of the function and it would be helpful to have DefaultBlockingExecutor dispatcher (BlockingPool?) available as object same way as we have CommonPool.
Also, I'm not sure that it's good, that we don't allow to pass custom context here because context can be used not only for dispatchers.
* @param executor the executor for blocking code | ||
* @param block the blocking code | ||
*/ | ||
suspend fun <T> blocking(executor: Executor = DefaultBlockingExecutor, block: () -> T) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think blocking should be covered by tests as well.
Hi @gildor, I wish receive some feedbacks about the future of this patch before continue the work. |
I'm sorry for dragging my feet for so long here. I did not saw it as improvement versus |
Added
blocking
andblockingAsync
suspending functions for blocking code invocation inside a coroutine.