Given such an example:
Mono.create(callback -> {
try { callback.success(someLogic()); }
catch (Exception e) { callback.error(e); }
})
.doFinally((v) -> Mono.fromRunnable(() -> {
Thread.sleep(1000); // In reality, we have a blocking I/O code here and needs to be executed on a separate thread
}).block())
.block();
When I run this code, it finishes immediately without waiting for the 1000ms delay. This is because doFinally is a side effect method, so it does not execute as part of the chain. Is there a finally like method that can execute as part of the chain?
My current workaround is
Mono.create(callback -> {
try { callback.success(someLogic()); }
catch (Exception e) { callback.error(e); }
})
.then(Mono.fromRunnable(() -> {
Thread.sleep(1000);
}))
.onErrorResume(e -> Mono.fromRunnable(() -> {
Thread.sleep(1000);
}))
.block();
If no such method is there a better approach?