Skip to content

Instantly share code, notes, and snippets.

@elevenetc
Created January 15, 2016 13:00
Show Gist options
  • Save elevenetc/839bbe4a3b7ec68580a9 to your computer and use it in GitHub Desktop.
Save elevenetc/839bbe4a3b7ec68580a9 to your computer and use it in GitHub Desktop.
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