I want to create my own `ContinuationInterceptor`,...
# coroutines
f
I want to create my own
ContinuationInterceptor
, but also use an existing
CoroutineDispatcher
to have all coroutines run on a specific thread. At first I thought I'd just extend
CoroutineDispatcher
, delegate everything and override
interceptContinuation
, but the interceptor methods are both final there. What's the recommended way of doing this, can I just combine the dispatcher and my interceptor?
s
You can create a single-threaded ExecutorService and then call asCoroutineDispatcher on it: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/as-coroutine-dispatcher.html
f
thats what I'm already doing. I also want some custom CoroutineInterceptor logic, that I'd like to "combine" with the dispatcher
s
Could you do something like this:
Copy code
class MyDispatcher(private val dispatcher: CoroutineDispatcher) : ContinuationInterceptor by dispatcher {
    override fun interceptContinuation(....) ....
}