Created
January 29, 2018 13:07
-
-
Save ShkurtiA/58adf1401c4e6ac0b4774c688aaa3666 to your computer and use it in GitHub Desktop.
Rxjava2 kotlin extension
This file contains hidden or 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
fun <T> Flowable<T>.applySchedulersIO(): Flowable<T> { | |
return subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()) | |
} | |
fun <T> Flowable<T>.applySchedulersComputation(): Flowable<T> { | |
return subscribeOn(Schedulers.computation()).observeOn(AndroidSchedulers.mainThread()) | |
} | |
fun <T> Flowable<T>.subscribeUIToIO(onNext: (T) -> Unit, onError: (Throwable) -> Unit): Disposable { | |
return applySchedulersIO().subscribe({ next -> | |
onNext(next) | |
}, { error -> | |
onError(error) | |
}) | |
} | |
fun <T> Flowable<T>.subscribeUIToComputation(onNext: (T) -> Unit, onError: (Throwable) -> Unit): Disposable { | |
return applySchedulersComputation().subscribe({ next -> | |
onNext(next) | |
}, { error -> | |
onError(error) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment