gpt4 book ai didi

java - 异步Java : How to return this without blocking?

转载 作者:行者123 更新时间:2023-12-02 01:28:00 25 4
gpt4 key购买 nike

设置:

public Mono<String> getResult(Mono<Boolean> flagMono, Mono<String> resultMono) {
return flagMono.map(flag -> {
if (flag) return "FLAG IS TRUE, SKIP RESULT";
return resultMono.block(); // how to do without blocking?
});
}

希望我想要完成的事情是清楚的,只需正确地写出来即可。如果flag为true,我想返回字符串常量,否则以非阻塞方式返回resultMono返回的字符串结果。

最佳答案

public Mono<String> getResult(Mono<Boolean> flagMono, Mono<String> resultMono) {
return flagMono.flatMap(flag -> {
if (flag) return Mono.just("FLAG IS TRUE, SKIP RESULT");
return resultMono;
});
}

关于java - 异步Java : How to return this without blocking?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56566989/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com