Created
June 26, 2016 11:17
-
-
Save AAverin/691c1b467fbf1b36027d2a16ff2599e8 to your computer and use it in GitHub Desktop.
gist for CleanAndroidCode article series https://medium.com/@anton.averin.dev/keep-your-droid-clean-e9c093140eb6
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
class ResolvedSubscriber<T> constructor( | |
val resolution: Resolution, | |
val onNextFunc: (T) -> Unit, | |
val onCompletedFunc: () -> Unit = {}, | |
val onErrorFunc: (Throwable?) -> Unit = {}) : Subscriber<T>() { | |
override fun onNext(p0: T) { | |
if (!isUnsubscribed) { | |
onNextFunc(p0) | |
} | |
} | |
override fun onCompleted() { | |
onCompletedFunc() | |
} | |
override fun onError(throwable: Throwable?) { | |
when (throwable) { | |
is HttpException -> resolution.onHttpException(throwable) | |
// let your location implementation throw a custom exception on timeout, for example | |
// is NetworkLocationTimeoutException -> resolution.onNetworkLocationError() | |
else -> throwable?.apply { resolution.onGenericRxException(this) } | |
} | |
onErrorFunc(throwable) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment