Zoltan Demant
03/04/2022, 6:25 AMFlow<T>
which queries data from an SQL database, initially emitting the current version of the data, and then emitting again anytime it changes. Is it possible to collect the flow in a way such that the initial query isnt re-ran everytime I restart collecting it?
Consider a component that can be started/stopped, if the initial query has finished it wouldnt make sense to re-run it the next time the component is started, Id much prefer to just receive any further changes to it. The natural approach seems to be collecting the flow in start, cancelling the resulting job in stop - as expected that restarts the collection everytime though.gildor
03/04/2022, 6:33 AMZoltan Demant
03/04/2022, 7:20 AMflow.buffer(1).shareIn(scope, Lazily)
? If I understand it correctly, the query will remain active and its last value will continiously be put in the shared-flow buffer, which the consumer component will receive when it resumes in collecting it?
I guess that would work, but what Im really after is also stopping the queries from running if there are no subscribers at the time. WhileSubscribed
sounds like it would do that, but it resets after a timeout and is similar to Lazily
with an infinite timeout (I think).gildor
03/04/2022, 7:27 AMCorrectsounds like it would do thatWhileSubscribed
gildor
03/04/2022, 7:28 AMbut it resets after a timeoutWhat do you mean? you can make it with or without timeout, up to you
Zoltan Demant
03/04/2022, 7:36 AMLazily
- stopTimeoutMillis=0 (default) => The counter would continue as long as the client is subscribed, but restart at 0 after every stoppage
What I actually want is for the counter to keep counting as long as someone is subscribed, pausing at the current number when the subscriber unsubscribes - and then continue counting from that number whenever that someone re-subscribes.gildor
03/29/2022, 3:25 AMgildor
03/29/2022, 3:44 AMZoltan Demant
03/29/2022, 5:46 AM