Hi, all
Recently I am learning how to use couchbase 4 with java SDK and I learn a lots from the tutorial.
But sometimes it got errors when I use the same code in tutorial, and I didn’t know how to solve it.
For example, in the tutorial Java SDK2.1 Updating documents chapter
the update document code that tutorial provided
bucket
.get(“id”)
.map(new Func1<JsonDocument, JsonDocument>() {
@Override
public JsonDocument call(JsonDocument document) {
modifyDocumentSomehow(document);
return document;
}})
.flatMap(new Func1<JsonDocument, Observable>() {
@Override
public Observable call(JsonDocument document) {
return bucket.replace(document);
}}).subscribe();
I have include couchbase-core-io-1.1.4.jar, couchbase-java-client-2.1.4.jar, rxjava-1.0.4.jar
It have compilation error in “map” and “return” in flatmap.
Here is my code with rewrite version from tutorial: QAm5sE - Online Java Compiler & Debugging Tool - Ideone.com
I don’t get it.
But if I add 2 async() methods to the position before get and the position in the flatmap’s return, It works fine as below
bucket
.async()
.get(“id”)
.map(new Func1<JsonDocument, JsonDocument>() {
…
})
.flatMap(new Func1<JsonDocument, Observable>() {
@Override
public Observable call(JsonDocument document) {
return bucket.async().replace(document);
}}).subscribe();
Why it can work but fail without async()?