重复可观察,除非被打断

Repeat observable unless interrupted

我如何创建一个 Observable 将重复 n 次,除非满足某些条件然后它应该被中断?

看起来像 repeatUnless 或类似的运算符。

有两种选择:

1) 如果要打断值序列:

source.repeat(n).takeWhile(condition);
source.repeat(n).takeUntil(condition);

2) 如果要重复n次或者直到某个条件不再满足:

source.repeatWhen(o -> o.scan(1, (a, b) -> a + 1).takeUntil(i -> i < n || condition)))