我正在使用一个数据库,并试图弄清楚如何同时执行具有 void 返回类型的写入。我已经按照 docs 包装了阻塞调用。
我想要:
从功能上来说,我可以使用它:
return repository
.get(param)
.flatMap(response -> Mono.zip(
method1(response),
method2(response),
(x, y) -> response
))
但是:
我觉得我正在滥用 Mono.zip 来订阅响应,因为我忽略了 x 和 y
我不得不更改method1/2接口,以在写入成功后任意返回一个值
这样做的正确方法是什么?
考虑到您描述的任务,我没有发现您的代码有任何问题。
但我认为可以通过
.thenReturn()
后备来简化:
return repository.get(param)
.flatMap(response -> Mono.zip(method1(response), method2(response))
.thenReturn(response)
)
response
将会在Mono.zip
完成后返还