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
Provide a clean way for Bridging Interceptors to get a cancel signal #7164
Comments
We might also want to give some way to access the EventListener (internal val on RealCall), if we'd like that to be part of the contract for these bridging interceptors. |
Also wondering when implementing an Interceptor in this new world. Is this a useful base class?
And should it cancel the runBlocking call automatically when the call is cancelled? Not an issue if you are blocking on the call or response, but if you are doing other work around the interceptor, including another forked request (auth) then the cancellation would be helpful. |
I suspect for bridging interceptors currently they end up looking like
|
I'm out of my depth writing a test for this, hence why it would be useful to have a solid library implementation to simplify these cases. |
Definitely runBlocking is wrong here. If you want to use coroutines in the call to |
Updated mine to runBlocking without IO. Not sure why runBlocking is wrong here, it achieves the same thing as the standard blocking call, uses the same thread, but allows you to do asynchronous operations elegently. runBlocking:
|
This post gets into it. Coroutines are cooperative multitasking. Running a blocking call or runBlocking inside a coroutine is uncooperative and bad non-local things can happen. |
I don't agree with all of that
According to docs, the thread doesn't sleep, it's a single threaded executor for the coroutines. So if the work remains non blocking, it shouldn't deadlock, and it shouldn't magically start using a bunch of extra threads. This sounds like what you want when you have a synchronous interface like Interceptor. For your comment:
Agreed, but that's not what I'm proposing. A blocking call to intercept that has nothing to do with the thread until it finishes, can donate that thread to run the coroutines. Uuugggghhhhh... I guess it breaks if the intercept method makes calls using enqueue, because they may not be processed immediately, so will waiting (noon-blockingly) for a request that can't complete until the call triggering intercept completes. |
Application Interceptor that use an alternate transport and short circuit the interceptor chain don't have a clean way to handle cancellation.
They can either poll the call, or possibly set a specific EventListener and handle the cancel event to get this signal.
The text was updated successfully, but these errors were encountered: