I want to understand why the timeout handler is invoked in below code. Since, I had configured the timeout of 100 seconds, I wasn't expecting the handler to be invoked as the element was being emitted after 1 second.
public static void main(String[] args) throws InterruptedException {
Mono<Integer> integerMono = Mono.just(1).delayElement(Duration.ofSeconds(1));
integerMono
.timeout(Duration.ofSeconds(100),handler())
.subscribe(integer -> System.out.println(integer));
Thread.sleep(10000);
}
private static Mono<? extends Integer> handler() {
System.out.println("handler invoked");
return Mono.just(10);
}
below is the output :
handler invoked
1
can someone please explain, why it's behaving so, and how do we achieve the expected behaviour?