Skip to content

Instantly share code, notes, and snippets.

@Diolor
Last active June 18, 2016 05:53
Show Gist options
  • Save Diolor/abde6dd10354b849a77b7a9060b3338c to your computer and use it in GitHub Desktop.
Save Diolor/abde6dd10354b849a77b7a9060b3338c to your computer and use it in GitHub Desktop.
Final example
private final PublishSubject<Void> viewClickedSubject = PublishSubject.create();
private final CompositeSubscription startStopCompositeSubscription = new CompositeSubscription();
@Override
protected void onStart() {
super.onStart();
view.setOnClickListener(v-> viewClickedSubject.onNext(null));
Subscription subscription = viewClickedSubject
.throttleFirst(200, TimeUnit.MILLISECONDS)
.switchMap(aVoid-> api.getAlert()
.retryWhen(RetryWithNetwork.create(context))
.retryWhen(RetryExponetialy.create())
)
.subscribe(
this::makeAlertToast,
throwable -> {
throw new OnErrorFailedException(" Unsubscribed from View click events.", throwable);
}
);
startStopCompositeSubscription.add(subscription);
}
@Override
protected void onStop() {
super.onStop();
startStopCompositeSubscription.clear();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment