Last active
December 20, 2018 12:38
-
-
Save VovaStelmashchuk/302f2320dd9d11958c324015677fc293 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* The method add default method [handleError] for handle onError evert from the ObservableSource, | |
* and add disposable from this subscribe to CompositeDisposable [compositeDisposable] | |
* | |
* @param onNext - the function you have designed to accept emissions from the ObservableSource | |
*/ | |
protected fun <T> Observable<T>.safeSubscribe(onNext: (T) -> Unit, onError: (Throwable) -> Unit = ::handleError) { | |
this.subscribe(onNext, onError) | |
.addToCompositeDisposable() | |
} | |
/** | |
* The method add default method [handleError] for handle onError evert from the SingleSource, | |
* and add disposable from this subscribe to CompositeDisposable [compositeDisposable] | |
* | |
* @param onNext - the function you have designed to accept emissions from the SingleSource | |
*/ | |
protected fun <T> Single<T>.safeSubscribe(onNext: (T) -> Unit, onError: (Throwable) -> Unit = ::handleError) { | |
this.subscribe(onNext, onError) | |
.addToCompositeDisposable() | |
} | |
protected fun Completable.safeSubscribe(onNext: () -> Unit, onError: (Throwable) -> Unit = ::handleError) { | |
this.subscribe(onNext, onError) | |
.addToCompositeDisposable() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment