Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Support optional thread interrupt in newSingleThreadContext as its friends #57
See discussion here: https://discuss.kotlinlang.org/t/calling-blocking-code-in-coroutines/2368
changed the title from
Support optional thread interrupt in newSingleThreadContext/newFixedThreadPoolContext
Support optional thread interrupt in newSingleThreadContext as its friends
Apr 17, 2017
@elizarov sorry to post here but I'm sure this could help a lot of other people.
I really struggle to understand how to properly cancel blocking IO calls since normal usage does not interrupt thread.
Goal would be convert some functions in a module to coroutines with blocking IO and some computation.
I get the isActive/yield and ways to cancel the computations, but not how to push the cancel to the blocking IO call.
If I understand correctly how to properly do the coroutines stuff it should be something like this
But from all that I read, cancelling the coroutine that call x() would still have to wait for the result to finish it's IO blocking call that only support thread interrupt)
Is there any usable documentation / sample that fully cover this need (for Android so without Guava if possible)
(Plan is not to use IO but an existing executor with asCoroutineDispatcher())