Created
March 29, 2012 15:29
-
-
Save cburgdorf/2238537 to your computer and use it in GitHub Desktop.
Strange Rx thing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mockFailingAjaxCall = function(){ | |
console.log("doing ajax call"); | |
var asyncSubject = new Rx.AsyncSubject(); | |
asyncSubject.onError(); | |
return asyncSubject.asObservable(); | |
}; | |
Rx.Observable.returnValue(1).select(function () { | |
return Rx.Observable.defer(function() { | |
return mockFailingAjaxCall(); | |
}) | |
.delay(1000) | |
.retry(3); | |
}) | |
.switchLatest() | |
.subscribe(function(){ console.log("on");}, function(e){console.log(e);}, function(){console.log("oc");}); | |
//In the above example its not respecting the 10 seconds delay | |
//I had to work around this using this code instead: | |
Rx.Observable.returnValue(1).select(function () { | |
return Rx.Observable.timer(1000).concat(Rx.Observable.defer(function() { | |
return mockFailingAjaxCall(); | |
})) | |
.skip(1) | |
.retry(3); | |
}) | |
.switchLatest() | |
.subscribe(function(){ console.log("on");}, function(){console.log("oe");}, function(){console.log("oc");}); |
I made the sample clearer. I'm projecting into an ajax call that fails and I want to retry the ajax calls but would like to put a delay between those calls. You can see that this doesn't work in the first example whereas it works for the second.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm not having any issues with that code. Here is my quick example where it respects the delay. Not sure why you're not seeing it. Full repro somewhere?