Last active
July 12, 2016 06:44
-
-
Save andrzejchm/b78bb7412d31078e4d8e9841401914a9 to your computer and use it in GitHub Desktop.
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
public class GetUserDetailsUsecase { | |
private final DB db; | |
@Inject public GetUserDetailsUsecase(DB db) { | |
this.db = db; | |
} | |
public Observable<UserDetails> getUserDetails() { | |
return Observable.create(new Observable.OnSubscribe<UserDetails>() { | |
@Override public void call(Subscriber<? super UserDetails> subscriber) { | |
try { | |
UserDetails userDetails = ... //retrieve data from database here | |
if (!subscriber.isUnsubscribed()) { | |
subscriber.onNext(userDetails); | |
subscriber.onCompleted(); | |
} | |
} catch (Exception ex) { | |
Log.e(ex, "error while retrieving user details"); | |
if (!subscriber.isUnsubscribed()) { | |
subscriber.onError(ex); | |
} | |
} | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment