I'm trying to understand to concepts behind reactive programming and currently i'm doing a JavaFX app what loads 3 random github users after a http request. I created an Observable that wraps the call to the github api(the api returns a list of 30elements) and from the response i want to extract the first 3 elements to place them in the page.
Observable<List<GitHubUser>> loadButtonObservable = JavaFxObservable
.actionEventsOf(runButton)
.flatMap(ae ->
Observable.fromCallable(() ->
githubExternalService.getUsersSince(
new Random().nextInt(500))));
loadButtonObservable
.take(1)
.map(list -> list.get(0))
.subscribe(i -> userOneVBox.getChildren().add(createText(i)));
loadButtonObservable
.skip(1)
.take(1)
.map(list -> list.get(0))
.subscribe(i -> userTwoVBox.getChildren().add(createText(i)));
loadButtonObservable
.skip(2)
.take(1)
.map(list -> list.get(0))
.subscribe(i -> userThreeVBox.getChildren().add(createText(i)));
I was expecting that when the button is clicked, the request is made and the subscribers receive the list of 30 elements, but instead the whole chain of observables is run from every subscriber. Could you help me understand how to structure the code so it will do 1 request instead of 3?