By default Completable is not hot. But I have case where hot Completable would be really useful: downloading and caching set of large files:
class DownloadManager {
Completable downloadAndCacheA();
Completable downloadAndCacheB();
}
Completable.merge(
downloadManager.downloadAndCacheA(),
downloadManager.downloadAndCacheB()
).subscribe();
When files are large user can leave the app and turn back. So client code can unsubscribe from these completables and subscribe again. One file can be downloaded, but another is still in progress. But as Completable is not hot downloading starts again.
Possible options is to:
Object.Thread instance with custom Completable which interact with each other.Don't really like all these solutions because of different reasons. Is there better way to support long running completable tasks?
Using cache, suggested by akarnokd, is probably the easiest way.
public Completable downloadAndCache() {
if (completable == null) {
completable = Completable.fromAction(this::syncDownloadAndCache)
.cache();
}
return completable;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With