Can you have multiple continuation interceptors?
e
Can you have multiple continuation interceptors?
z
Yea but you need to make sure to pull the existing one out and wrap it before adding another, last time I checked anyway
e
Copy code
class DelegateInterceptor(
    private val delegate: ContinuationInterceptor
) : ContinuationInterceptor by delegate {
    companion object : Key<DelegateInterceptor>
    override val key = DelegateInterceptor

    override fun <T> interceptContinuation(continuation: Continuation<T>): Continuation<T> {
        println("Intercepting continuation")
        return delegate.interceptContinuation(continuation)
    }
    override fun releaseInterceptedContinuation(continuation: Continuation<*>) {
        println("Relasing continuation")
        delegate.releaseInterceptedContinuation(continuation)
    }
    override fun toString() = "DelegateInterceptor[$delegate]"
}
Humm if I do this:
Copy code
fun main() = runBlocking {
    withContext(DelegateInterceptor(coroutineContext[ContinuationInterceptor]!!)) {
       ...
    }
}
It never seems to get called, but I'm not sure how else to get the runBlocking context here
z
Doesn't the key need to be
ContinuationInterceptor.Key
?
e
Tried that as well, interestingly no matter what key you pass in if you do:
Copy code
runBlocking(SomeInterceptorWithAKey()) {
  println(coroutineContext[ContinuationInterceptor])
}
seems to print SomeInterceptorWithAKey