请帮助我使用反应器,我需要最多检查一个条件 n 次并返回最终结果
我发现reactor有reactor-extra模块
https://projectreactor.io/docs/extra/snapshot/api/reactor/retry/Repeat.html
它具有构造
Repeat.create(java.util.function.Predicate<? super RepeatContext<T>> predicate, long n)
Repeat 函数,仅当谓词返回 true 时才重复 n 次。
这看起来是正确的解决方案,但我不明白
我想重复的操作应该在哪里?我有很多动作的 Flux,但我只想重复一个
请举一个代码示例
谢谢
private int culculateNextResult(some params) {
// some implementation
}
private Boolean compareResults(int prevRes, int nextRes) {
// some implementation
}
public Flux<Boolean> run(some params, Flux<Integer> prevResults){
return prevResults.map(elem -> compareResults(elem, culculateNextResult(some params)));
// THIS LOGIC SHOULD BE REPEATED N times if compareResults(elem,
// culculateNextResult(some params))) == false, if true, we don't need
// to repeat
}
Run Code Online (Sandbox Code Playgroud)
我想重复compareResults(elem, …