Closed bobziuchkovski closed 4 years ago
Thanks! I've been reluctant to add this to the core library for a couple reasons:
ImageLoader
interface very minimal with only 3 main methods (not counting properties): enqueue
/execute
/shutdown
(similar to OkHttp).suspend
functions instead of making it easy to block the thread.XYZBlocking
functions (e.g. Transformation.transformBlocking
, Fetcher.fetchBlocking
, Decoder.decodeBlocking
, etc.)That said, you bring up a good point that Java-only users can't use execute
without either adding the Kotlin plugin to their current module (and slowing their build) or creating a separate module. Even though Coil is Kotlin-first, I think that the core functionality (e.g. creating an ImageRequest
+ enqueuing
/executing
it) should work with Java out of the box.
Going to think about this a bit more, but if it's added I think it makes sense to keep it as an extension function callable from Java: val result = ImageLoaders.executeBlocking(imageLoader, request)
.
An extension function sounds completely reasonable. I totally understand the kotlin-first approach and wouldn't argue for the need to support java for everything, but it did strike me as weird to need to add kotlin on my end for blocking requests.
In any event, thanks for the thoughtful response and for taking the time to consider it.
Added this - it'll be out in rc3
. Thanks again for the feedback!
Is your feature request related to a problem? Please describe. Yes. I have a pure Java android project and I'm using rxjava worker threads for background image retrieval. I would like to fetch images synchronously on these threads with coil.
Describe the solution you'd like Rather than document the (admittedly trivial) solution for performing blocking requests from Java, add this to the core library as
ImageLoader.executeBlocking
and update the documentation to reflect this.Additional context For now I've added a kotlin module to my project for implementing this behavior, but it seems kind of silly to add an entire kotlin module for this functionality. If the use case is common enough to call out in the documentation, it seems like it'd make sense to add it to the core library.
In any event, kudos on an amazing library. I've thoroughly evaluated Glide, Fresco, and Coil, and Coil is already a clear winner.