HooMin.Lee
HooMin.Lee

Reputation: 147

How do I compare the values in 'Mono'?

Comparing the values in Mono<Integer> a and Mono<Integer> b, if the value in Mono<Integer> a is larger, I want to throw an error.

Mono<Integer> a = getA();
Mono<integer> b = getB();

if(a > b) {
 throw new RuntimeException();
}

Upvotes: 2

Views: 1491

Answers (1)

Alan Rusnak
Alan Rusnak

Reputation: 247

Mono<Integer> a = Mono.just(12);
Mono<Integer> b = Mono.just(10);

a.zipWith(b)
    .doOnNext(tuple -> {
        if (tuple.getT1() > tuple.getT2()) {
            throw new RuntimeException();
        }
    }).subscribe();

Upvotes: 3

Related Questions