1 回答

TA贡献1876条经验 获得超7个赞
发生这种情况是因为flatMap用于并发处理 observables 而您需要顺序。要解决这个问题,您只需要更改您的flatMaptoconcatMap以确保您的getCorrectSafeCombination方法中可观察的顺序流:
Maybe<Integer> getCorrectSafeCombination() {
return getPossibleCombinations()
.toObservable()
.flatMapIterable(combinations -> combinations)
//this one
.concatMap(combination -> tryToOpenSafeWithCombination(combination).toObservable()
.map(isCorrect -> new CombinationCheckResult(combination, isCorrect)))
.filter(result -> result.isCorrect)
.map(result -> result.combination)
.firstElement();
}
添加回答
举报