coil-base / coil / ImageLoader / Builder / launchInterceptorChainOnMainThread

launchInterceptorChainOnMainThread

fun launchInterceptorChainOnMainThread(enable:Boolean): Builder

Enables launching the Interceptor chain on the main thread.

If true, the Interceptor chain will be launched from MainCoroutineDispatcher.immediate. This allows the ImageLoader to check its memory cache and return a cached value synchronously if the request is started from the main thread. However, Mapper.map and Fetcher.key operations will be executed on the main thread as well, which has a performance cost.

If false, the Interceptor chain will be launched from the request's ImageRequest.dispatcher. This will result in better UI performance, but values from the memory cache will not be resolved synchronously.

The actual fetch + decode process always occurs on ImageRequest.dispatcher and is unaffected by this flag.

It's worth noting that Interceptors can also control which CoroutineDispatcher the memory cache is checked on by calling Interceptor.Chain.proceed inside a withContext block. Therefore if you set launchInterceptorChainOnMainThread to true, you can control which ImageRequests check the memory cache synchronously at runtime.

Default: true