I'm trying to use RxJS for a simple short poll. It needs to make a request once every delay
seconds to the location path
on the server, ending once one of two conditions are reached: either the callback isComplete(data)
returns true or it has tried the server more than maxTries
. Here's the basic code:
newShortPoll(path, maxTries, delay, isComplete) {
return Observable.interval(delay)
.take(maxTries)
.flatMap((tryNumber) => http.get(path))
.doWhile((data) => !isComplete(data));
}
However, doWhile doesn't exist in RxJS 5.0, so the condition where it can only try the server maxTries
works, thanks to the take() call, but the isComplete
condition does not work. How can I make it so the observable will next() values until isComplete returns true, at which point it will next() that value and complete().
I should note that takeWhile()
does not work for me here. It does not return the last value, which is actually the most important, since that's when we know it's done.
Thanks!