You may place conditional statements to flatMap
and use switchIfEmpty to return other publisher. A short example:
myService.executeWc1() // returns Mono
.flatMap(result -> myService.executeWc2(result))
.flatMap(result -> validator.validate(result))
.handle((result, sink) -> {
if (result) { // validation is passed
sink.success(true);
}
sink.success();
})
.flatMap(result -> myService.doSomeWork()
.flatMap(r -> myService.executeWc3())
.flatMap(r -> myService.doSomeWorkAgain())
.flatMap(r -> myService.executeWc4()))
.switchIfEmpty(myService.executeWc4())
and so on...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…