I am trying to use RxJS for a simple short poll. It should make a request once every delay seconds to the path location on the server, ending after one of two conditions is reached: either the isComplete(data) callback returns true, or the server tried more than maxTries . Here is 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 does not exist in RxJS 5.0, so the condition that it can only try the maxTries server maxTries working, thanks to the take () call, but the isComplete condition isComplete not working. How can I make the observed next () values ββchange until isComplete returns true, and at that moment it will be the next () this 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, as we know it.
Thanks!
source share