Skip to content

Instantly share code, notes, and snippets.

@maoruibin
Last active January 21, 2016 04:15
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 maoruibin/fcd1836fd5237b56cb51 to your computer and use it in GitHub Desktop.
Save maoruibin/fcd1836fd5237b56cb51 to your computer and use it in GitHub Desktop.
RxUtils
/**
* make a operate change to observable
* @param func
* @param <T>
* @return
*/
public static <T> Observable<T> makeObservable(final Callable<T> func) {
return Observable.create(new Observable.OnSubscribe<T>() {
@Override
public void call(Subscriber<? super T> subscriber) {
try {
subscriber.onNext(func.call());
} catch (Exception e) {
subscriber.onError(e);
}
subscriber.onCompleted();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment