coil-kt / coil

Image loading for Android and Compose Multiplatform.

Home Page:https://coil-kt.github.io/coil/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Suspending mapping of image data

saket opened this issue · comments

Hey Colin, I'm trying to add support for generating previews of adaptive videos in my app. Unlike direct images and videos, this involves making a second network call for extracting a video for the requested size. I'm not too familiar with Coil's internals, but it seems like doing this in a Mapper is my best option because any value returned from a Mapper gets cached for free.

Unfortunately, Mapper runs on the main thread by default so any network calls can't be made. I am aware that I could set interceptorDispatcher to workaround this, but I also like Coil's ability to synchronously load images. Could Mapper be made suspending to solve this?

I just realized that Coil's checks its memory cache after data is already mapped so my proposal for making Mapper#map suspending wouldn't make sense either.

I was able to make this work by moving my code to a Fetcher.Factory instead.