Skip to content

Instantly share code, notes, and snippets.

@cburgdorf
Created March 29, 2012 15:29
Show Gist options
  • Save cburgdorf/2238537 to your computer and use it in GitHub Desktop.
Save cburgdorf/2238537 to your computer and use it in GitHub Desktop.
Strange Rx thing
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");});
@mattpodwysocki
Copy link

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?

Rx.Observable.returnValue(1).select(function (x) {
    return Rx.Observable.returnValue(x).delay(10000).retry(3);
}).switchLatest().subscribe(function (x) {
    console.log(x);
});

@cburgdorf
Copy link
Author

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