How to make void async touch better, do not need the results Java


#1

I have a way to update exiparion for collection of Documents in Java:

 for (String key : keys) {
        try {
            getBucket().async().touch(key, defaultExpiry).subscribe();

} catch(…){

}
}

Is it correct ? I am not sure how to work with void async methods.

Please advice, what is the best approach.

Thank you


#2

Hi @ekaterina.mayer6, that will work, but this is a touch more efficient:

Observable.from(keys)
            .flatMap(key -> {
                return getBucket.async().touch(key, defaultExpiry);
            })
            .subscribe();

#3

Hi, thanks a lot.
Can you please explain why it is better ?
Or give me the links to documentation where I can find the answer ?

Is you approach is better from performance perspective ?

Also, I am interested in the more efficient and better way to insert one document async with no expecting any return value.

getBucket().async().insert(jsonDocument).subscribe();

Is it enough ?

Sincerely, Kate