Skip to content

Instantly share code, notes, and snippets.

@jpetitto
Created November 5, 2015 16:35
Show Gist options
  • Save jpetitto/b2e0a532fa63b59576aa to your computer and use it in GitHub Desktop.
Save jpetitto/b2e0a532fa63b59576aa to your computer and use it in GitHub Desktop.
Polling at Dynamic Rate with RxJava
BehaviorSubject<Integer> timerSubject = BehaviorSubject.create(1);
timerSubject
.switchMap(interval -> Observable.timer(interval, TimeUnit.SECONDS, Schedulers.newThread()))
.flatMap(i -> Observable.just(randomInt()))
.doOnNext(timerSubject::onNext)
.subscribe(System.out::println);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment