Observable<Entry<GeoCircleValue<String>> results = tree.search(...);
results
//get just the name of the city
.map( entry -> entry.value().value)
//get the populations asynchronously
.flatMap(name -> Observable.just(name)
.map(n -> new NameAndPop(n, service.populationOf(n))
.subscribeOn(Schedulers.io()))
//observe the results on current thread
.observeOn(Schedulers.immediate())
//write the name and the population to the servlet writer
.subscribe(Subscribers.create(namePop -> out.println(<"p>" + namePop.name() + " " + namePop.pop() + "</p>"));
Last active
August 29, 2015 14:11
-
-
Save davidmoten/de069c45ecbd01e8bd5a to your computer and use it in GitHub Desktop.
rxjava example
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment