Last active
June 2, 2017 13:10
-
-
Save ultraon/502d4fb68ee5f1f3308904c6735ff44e to your computer and use it in GitHub Desktop.
The {@link IoToMainThreadTransformers} is a factory of convenient Rx transformers to use with {@link io.reactivex.Observable#compose(ObservableTransformer)} operator to transform observable via apply {@link io.reactivex.Observable#subscribeOn(Scheduler)} operator with the {@link Schedulers#io()} and {@link io.reactivex.Observable#observeOn(Sche…
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
/** | |
* The {@link IoToMainThreadTransformers} is a factory of convenient Rx transformers to use with {@link | |
* io.reactivex.Observable#compose(ObservableTransformer)} operator to transform observable via | |
* apply {@link io.reactivex.Observable#subscribeOn(Scheduler)} operator with the {@link | |
* Schedulers#io()} and {@link io.reactivex.Observable#observeOn(Scheduler)} operator with the | |
* {@link AndroidSchedulers#mainThread()}. | |
*/ | |
public final class IoToMainThreadTransformers { | |
private IoToMainThreadTransformers() { | |
throw new AssertionError("Not instantiated class"); | |
} | |
/** | |
* Creates the {@link ObservableTransformer} to transform observable via apply {@link | |
* io.reactivex.Observable#subscribeOn(Scheduler)} operator with the {@link Schedulers#io()} and {@link | |
* io.reactivex.Observable#observeOn(Scheduler)} operator with the {@link | |
* AndroidSchedulers#mainThread()}. | |
* | |
* @param <T> the type of emitting value | |
* @return the {@link ObservableTransformer} to use | |
*/ | |
@NonNull | |
public static <T> ObservableTransformer<T, T> ofObservable() { | |
return upstream -> upstream.subscribeOn(Schedulers.io()).observeOn( | |
AndroidSchedulers.mainThread()); | |
} | |
/** | |
* Creates the {@link FlowableTransformer} to transform observable via apply {@link | |
* io.reactivex.Flowable#subscribeOn(Scheduler)} operator with the {@link Schedulers#io()} and {@link | |
* io.reactivex.Flowable#observeOn(Scheduler)} operator with the {@link | |
* AndroidSchedulers#mainThread()}. | |
* | |
* @param <T> the type of emitting value | |
* @return the {@link FlowableTransformer} to use | |
*/ | |
@NonNull | |
public static <T> FlowableTransformer<T, T> ofFlowable() { | |
return upstream -> upstream.subscribeOn(Schedulers.io()).observeOn( | |
AndroidSchedulers.mainThread()); | |
} | |
/** | |
* Creates the {@link MaybeTransformer} to transform observable via apply {@link | |
* io.reactivex.Maybe#subscribeOn(Scheduler)} operator with the {@link Schedulers#io()} and {@link | |
* io.reactivex.Maybe#observeOn(Scheduler)} operator with the {@link | |
* AndroidSchedulers#mainThread()}. | |
* | |
* @param <T> the type of emitting value | |
* @return the {@link MaybeTransformer} to use | |
*/ | |
@NonNull | |
public static <T> MaybeTransformer<T, T> ofMaybe() { | |
return upstream -> upstream.subscribeOn(Schedulers.io()).observeOn( | |
AndroidSchedulers.mainThread()); | |
} | |
/** | |
* Creates the {@link SingleTransformer} to transform observable via apply {@link | |
* io.reactivex.Single#subscribeOn(Scheduler)} operator with the {@link Schedulers#io()} and | |
* {@link io.reactivex.Single#observeOn(Scheduler)} operator with the {@link | |
* AndroidSchedulers#mainThread()}. | |
* | |
* @param <T> the type of emitting value | |
* @return the {@link SingleTransformer} to use | |
*/ | |
@NonNull | |
public static <T> SingleTransformer<T, T> ofSingle() { | |
return upstream -> upstream.subscribeOn(Schedulers.io()).observeOn( | |
AndroidSchedulers.mainThread()); | |
} | |
/** | |
* Creates the {@link CompletableTransformer} to transform observable via apply {@link | |
* io.reactivex.Completable#subscribeOn(Scheduler)} operator with the {@link Schedulers#io()} and | |
* {@link io.reactivex.Completable#observeOn(Scheduler)} operator with the {@link | |
* AndroidSchedulers#mainThread()}. | |
* | |
* @return the {@link CompletableTransformer} to use | |
*/ | |
@NonNull | |
public static CompletableTransformer ofCompletable() { | |
return upstream -> upstream.subscribeOn(Schedulers.io()).observeOn( | |
AndroidSchedulers.mainThread()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment