Skip to content

Instantly share code, notes, and snippets.

@tonypiazza
Last active August 29, 2015 14:17
Show Gist options
  • Save tonypiazza/550f222b3bd608b612eb to your computer and use it in GitHub Desktop.
Save tonypiazza/550f222b3bd608b612eb to your computer and use it in GitHub Desktop.
Here is an example of using RxJava via the Couchbase Java SDK.
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