Skip to content

Instantly share code, notes, and snippets.

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 AAverin/691c1b467fbf1b36027d2a16ff2599e8 to your computer and use it in GitHub Desktop.
Save AAverin/691c1b467fbf1b36027d2a16ff2599e8 to your computer and use it in GitHub Desktop.
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