Created
January 15, 2016 13:00
-
-
Save elevenetc/839bbe4a3b7ec68580a9 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
import rx.Observable; | |
import rx.Subscription; | |
import rx.android.schedulers.AndroidSchedulers; | |
import rx.functions.Action1; | |
import rx.schedulers.Schedulers; | |
/** | |
* Created by levenetc on 23/06/15. | |
*/ | |
public class RXUtils { | |
static Observable.Transformer schedulersTransformer = new Observable.Transformer<Object, Object>() { | |
@Override public Observable<Object> call(Observable<Object> observable) { | |
return observable | |
.subscribeOn(Schedulers.io()) | |
.observeOn(AndroidSchedulers.mainThread()); | |
} | |
}; | |
public static void disableScgedulersTransformer() { | |
schedulersTransformer = new Observable.Transformer<Object, Object>() { | |
@Override public Observable<Object> call(Observable<Object> observable) { | |
return observable; | |
} | |
}; | |
} | |
@SuppressWarnings("unchecked") | |
public static <T> Observable.Transformer<T, T> applySchedulers() { | |
return (Observable.Transformer<T, T>) schedulersTransformer; | |
} | |
public static void unsubscribe(Subscription... subscriptions) { | |
if (subscriptions != null) | |
for (Subscription sub : subscriptions) | |
if (sub != null) sub.unsubscribe(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment