Rx repeat observable every amount of time with stop and resumefrom the CommonsWare Community archives
At February 28, 2020, 2:22pm, islam.farid2100 asked:
I have a webservice Api which return an observable and I want to call it every 10 seconds with the option to stop and resume and totally unsubscribe. Is there any example or hint to follow.
At February 28, 2020, 5:12pm, mmurphy replied:
Note: I am not an RxJava expert.
If you want an
Observable that emits every 10 seconds, use
interval(). If you want to keep the timer but ignore some events (“stop and resume”), add a
filter() that filters events based on your stop/resume state. To “totally unsubscribe”, dispose the
Disposable that you get when you
subscribe() to the Rx chain.
At February 29, 2020, 5:44am, islam.farid2100 replied:
Thank you very much indeed for ur fast reply. I believe that filter will call the webservice and will not stop, so I may unsubscribe and resubscribe
At February 29, 2020, 11:56am, mmurphy replied:
If you put the filter between the
interval() and the
flatMap() (or whatever you are doing to chain in the Web service call), then the Web service would not be called when the
At March 3, 2020, 12:19pm, islam.farid2100 replied:
it worked, thank you very much indeed