Other implementations of Rx have the repeatWhen operator, which allows the repetition to be controlled by another Observable. Very convenient.
It is quite different from repeat in that a/ you can control the flow of repetitions and b/ you can interrupt it.
The implementation would probably take from repeat but not entirely, as it requires to delay the scheduleRecursive call until a new event was received from the control Observable, and also to resubscribe to the original source instead of re-emitting the same event.
Does retryWhen not do the same thing?
@smaspe could you maybe explain more about the context for which you need repeatWhen. I would first like to understand how common your need is :)
@thanegill no, because retryWhen requires the source to error. (but similar)
@kzaher sure! It is used in a polling system. The control Observable is able to trigger a single repeat from the source Observable.
The control Observable can then be bound to either a timed interval, a user action, ...
@thanegill Actually transforming the Completed event into a specific Error event on the source Observable allows to use retryWhen. A bit of a hack, though.
Hi @smaspe,
I think we would need to refactor retryWhen to accommodate that new functionality. I'll try to find time to investigate RxJava to see how they've organized their code, find proper unit tests and see what can we learn from them.
That will probably take some time since I'll need to find time for investigations and those refactorings, but I'll see what we can do here in the long run.
@kzaher thanks for taking that into consideration! much appreciated!
+1 to this feature request 鈥斅營'm doing something very similar (polling system).
I think that right now you can just do something like:
struct InfiniteSequence<E> : SequenceType {
typealias Element = E
typealias Generator = AnyGenerator<E>
private let _repeatedValue: E
init(repeatedValue: E) {
_repeatedValue = repeatedValue
}
func generate() -> Generator {
let repeatedValue = _repeatedValue
return anyGenerator {
return repeatedValue
}
}
}
and then
InfiniteSequence(sourceSequence.takeWhile { x in x is correct }).concat()
I believe this is worthy of inclusion in the core library.
I would like this as well! Would be super useful
Me too! It would be awesome, but this is from 2016 so I don't think it will be done soon... :/
I'm closing this for now due to inactivity - If you have any more comments on this subject, feel free to comment or ping me directly and I'll re-open it :) Thanks !
Most helpful comment
I think that right now you can just do something like:
and then