Created
December 28, 2015 13:19
-
-
Save jiangecho/1cd6d8df0cbcb694d380 to your computer and use it in GitHub Desktop.
create an observable from callback.
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
public Observable<String> doAmazingThingObservable(int param) { | |
return Observable.create(new Observable.OnSubscribe<String>() { | |
@Override | |
public void call(Subscriber<? super String> subscriber) { | |
doAmazingThing(param, new CallBack() { | |
@Override | |
public void onGotResult(String result) { | |
if (result == null) { | |
if (!subscriber.isUnsubscribed()) { | |
subscriber.onError(new SomeException()); | |
} | |
} else { | |
if (!subscriber.isUnsubscribed()) { | |
subscriber.onNext(result); | |
subscriber.onCompleted(); | |
} | |
} | |
} | |
}); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment