Status Update
Comments
mu...@gmail.com <mu...@gmail.com> #2
Just realized that flow related methods should be exposed from work-runtime-ktx
and Flowable type methods from work-rxjava2
.
ra...@google.com <ra...@google.com> #3
LiveData
already provides a way to convert itself to a ReactiveStreams Publisher
using
Once you have an instance of Publisher
you can use Rx APIs to get a Flow
.
mu...@gmail.com <mu...@gmail.com> #4
There is a lot of overhead in that and unnecessary thread switching. Actually I wrote an extention function for LiveData to convert into Flow, so my problem is solved now.
Still considering other libraries from Google like Room has first party support for Flowable and Flow, I expected it from WorkManager too. And internally WorkManager uses Room to store and retrieve WorkInfo, so it should be possible.
bo...@gmail.com <bo...@gmail.com> #5
This is definitely something that should be included in the ktx
module. Right now I can convert LiveData to Flow with asFlow()
, but as said earlier this still has more overhead than necessary. Ideally I'd like LiveData support moved to a separate module as well, since WorkManager is the only library I have now that still depends on LiveData.
If we can get an update on this, that would be great!
ax...@gmail.com <ax...@gmail.com> #6
ey...@gmail.com <ey...@gmail.com> #7
Pushing this complexity to the developers is a mistake, especially because it can blow up at runtime if the LiveData isn't observed (or the observer removed) correctly.
The whole industry is moving on from LiveData. It's crazy that the current solution is LiveData -> Publisher -> Flow.
Description
Component used: work-runtime Version used: 2.3.4 Devices/Android versions reproduced on: All devices and all versions
Currently work info is exposed as
ListenableFuture
andLiveData
. I have an use case where I publish progress from worker and I need to do some computation for each progress before showing the progress on UI. I need to move the computation part to background thread.Since LiveData only publishes data in main thread, there is unnecessary thread switching if I do the computation from there in background thread. And the code for this is not pretty either. I need to use a channel or subject to capture values from LiveData and do the computation from that and publish the results.
It would be better if there are additional methods in
WorkManager
likegetWorkInfoByIdFlow
,getWorkInfoByIdFlowable
,getWorkInfosByTagFlow
,getWorkInfosByTagFlowable
etc.