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 optional thread interrupt in newSingleThreadContext as its friends #57

Open
elizarov opened this Issue Apr 17, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@elizarov
Collaborator

elizarov commented Apr 17, 2017

@elizarov elizarov changed the title from Support optional thread interrupt in newSingleThreadContext/newFixedThreadPoolContext to Support optional thread interrupt in newSingleThreadContext as its friends Apr 17, 2017

@elizarov elizarov added the enhancement label Nov 6, 2017

@Tolriq

This comment has been minimized.

Tolriq commented Oct 28, 2018

@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

suspend fun x(): y {
   ....
   val result = withContext(IO) {
   }
   do CPU computation checking for isActive()/yield
}

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())

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