ContinuationInterceptor

As we discussed earlier in the book, the CoroutineContext behaves like a map where all the different CoroutineContext.Element are stored with their own unique key. One of those elements is defined by the ContinuationInterceptor interface. Let's take a look at it:

public interface ContinuationInterceptor : CoroutineContext.Element {
companion object Key : CoroutineContext.Key<ContinuationInterceptor>
fun <T> interceptContinuation(cont: Continuation<T>): Continuation<T>
}

Notice that apart from its key, it only defines a function that takes a continuation and returns another. The idea is for the implementation of ContinuationInterceptor to wrap the received continuation into another, one that is intercepted in order to guarantee that the correct thread is used.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.106.233