Skip to content

Instantly share code, notes, and snippets.

@anitaa1990
Created August 19, 2018 06:11
Show Gist options
  • Save anitaa1990/3413a914cc200aab1147f4d4fb3b95d2 to your computer and use it in GitHub Desktop.
Save anitaa1990/3413a914cc200aab1147f4d4fb3b95d2 to your computer and use it in GitHub Desktop.
/*
* There are 2 Observables each emitting values after an interval of 100 ms and 150 ms
* respectively. The combineLatest() operator combines both the observables and
* emits the result at each particular intervals.
*/
Observable<Long> observable1 = Observable.interval(100, TimeUnit.MILLISECONDS);
Observable<Long> observable2 = Observable.interval(50, TimeUnit.MILLISECONDS);
Observable.combineLatest(observable1, observable2,
(observable1Times, observable2Times) ->
"Refreshed Observable1: " + observable1Times + " refreshed Observable2: " + observable2Times)
.subscribe(item -> System.out.println(item));
Thread.sleep(1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment