Last active
August 29, 2015 14:17
-
-
Save tonypiazza/550f222b3bd608b612eb to your computer and use it in GitHub Desktop.
Here is an example of using RxJava via the Couchbase Java SDK.
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 Iterable<Playlist> findByUserName(String userName) { | |
return getBucketFactory() | |
.getAsyncBucket(Playlist.class) | |
.flatMap(bucket -> bucket | |
.get(USER_PREFIX + userName) | |
.flatMap(doc -> | |
Observable.from(doc.content().getArray(PLAYLISTS_PROPERTY)) | |
) | |
.flatMap(id -> bucket.get(id.toString())) | |
.map(doc -> fromJsonObject(doc.content(), Playlist.class)) | |
.timeout(1, TimeUnit.SECONDS) | |
.onErrorResumeNext(t -> | |
Observable.error(new RepositoryException(t)) | |
) | |
) | |
.toBlocking() | |
.toIterable(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment