question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to implement polling using Observables?

See original GitHub issue

I’ve got parametrized rest call with Observable interface:

   api.updateAppState(params);

I want to repeat it with delay so I have created delayed version of it:

   Observable<AppState> delayedApiCall = Observable.interval(delay, TimeUnit.SECONDS)
            .first()
            .flatMap(new Func1<Long, Observable<AppState>>() {
        @Override
        public Observable<AppState> call(Long seconds) {
            return lyftApi.updateAppState(params);
        }
    });

But now I want to have polling observable that will recreate “delayedApiCall” with params and produce continuous results. I also want observable to continue producing results even if error was returned in “delayedApiCall”.

    pollingObservable.subscribe(new Observer<AppState>() {
        onNext(AppState appSte) {
           ....
        },
        onError(Throwable e) {
           ....
        }
    });

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:20 (8 by maintainers)

github_iconTop GitHub Comments

39reactions
akarnokdcommented, Jul 18, 2016

Okay then, how about:


Observable.fromCallable(() -> pollValue())
.repeatWhen(o -> o.concatMap(v -> Observable.timer(20, TimeUnit.SECONDS)));
7reactions
akarnokdcommented, Jul 17, 2016

Use Observable.interval() as the starting point and forget that manual recursion.

Observable.interval(1, TimeUnit.SECONDS, Schedulers.io())
.map(time -> pollSource())
.toBlocking()
.subscribe(System.out::println, Throwable::printStackTrace)
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to do polling with RxJs and Angular? | by Alain Chautard
In this tutorial, we're going to implement a polling mechanism using RxJs and Angular. Our goal is to retrieve and render information that ......
Read more >
Http Polling - Learn RxJS
This recipe demonstrates one way you can achieve polling an HTTP endpoint on an ... import { Observable, Subscription, of, fromEvent, from, empty,...
Read more >
Polling in Angular — How to use RxJS in Angular for polling?
In this component file, we are implementing the polling using RxJS. Here the interval is an Observable and is piped to execute the...
Read more >
Polling using RxJS. As observables are gaining more and…
We will walk through an example of such a scenario and implement a solution using RxJS. On our way we will learn some...
Read more >
Implement Polling Using RxJS in Your Angular Application
In this article, we will implement polling logic using RxJS. ... Create an observable that emits values on continuous intervals using the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found