Skip to content

Instantly share code, notes, and snippets.

@feresr
Last active January 30, 2017 21:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save feresr/b1e1045d175eae60f4fdce054fa9b6f9 to your computer and use it in GitHub Desktop.
Save feresr/b1e1045d175eae60f4fdce054fa9b6f9 to your computer and use it in GitHub Desktop.
multicast3
Observable<Data> dataStream = RxView.clicks(button)
.observeOn(Schedulers.io())
.debounce(2, TimeUnit.SECONDS)
.flatMap(new Func1<Void, Observable<Data>>() {
@Override
public Observable<Data> call(Void aVoid) {
Log.d(TAG, "Performing network request...");
return apiEndpoints.getData();
}
})
.publish().autoConnect(2) // <-- NEW LINE
.observeOn(AndroidSchedulers.mainThread());
dataStream.subscribe(data -> Log.d(TAG, "View one received the data"));
dataStream.subscribe(data -> Log.d(TAG, "View two received the data"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment