Fetch: hasActiveDownloads as Observable/Flowable

Created on 2 Apr 2019  路  6Comments  路  Source: tonyofrancis/Fetch

Hello Tony.
There is any way I can use hasActiveDownloads as an Observable/Flowable?

I was debugging my app to fix an issue and I saw that FetchHandlerImpl throws an exception if the call is done on the main thread. (as mentioned by you here as well https://github.com/tonyofrancis/Fetch/issues/297)
override fun hasActiveDownloads(): Boolean { if (Thread.currentThread() == Looper.getMainLooper().thread) { throw FetchException(BLOCKING_CALL_ON_UI_THREAD) } return databaseManager.getPendingCount() > 0 }

but RxFetchImpl catches the exception and returns false.
override val hasActiveDownloads: Boolean get() { return try { fetchHandler.hasActiveDownloads() } catch (e: Exception) { false } }

I think this might create some confusion with hasActiveDownloads returning false because the contract is not being followed correctly. My suggestion would be to propagate the exception.

enhancement help wanted

All 6 comments

@gbirk nice catch on the behavior. I will fix in the next release.hasActiveDownloads(): Boolean will be depricated soon. Use the new RxFetch.hasActiveDownloads(includeAddedDownloads: Boolean): Convertible<Boolean> method instead.

Are you planning on having a hasActiveDownloads that doesn't complete the Observer after returning? Something that we can use to subscribe and keep listening for state updates?

@gbirk I see what you are saying. Mhm let me look into this for the next release.

@gbirk Fetch version 3.0.4 has been released with a new method fun addActiveDownloadsObserver(includeAddedDownloads: Boolean = false, fetchObserver: FetchObserver<Boolean>): Fetch added to fetch. This uses a fetch observer for the update. The Fetch Observer is notified every 5 minutes by default. You can change this by setting the interval on the Fetch configuration. fetchConfiguration.setHasActiveDownloadsCheckInterval(intervalInMillis)

Thanks @tonyofrancis, I'll give it a try as soon as possible.

Hi @tonyofrancis. The feature is working as expected. I ended up implementing in a different way. I register the fetch observer to keep listening for changes, then I update my own PublishSubject. This subject can be used to subscribe with distinctUntilChanged() to receive events only when there is a change.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jpvs0101 picture jpvs0101  路  3Comments

jpvs0101 picture jpvs0101  路  5Comments

burhanaksendir picture burhanaksendir  路  4Comments

maulik9898 picture maulik9898  路  4Comments

rs-georg picture rs-georg  路  4Comments