Skip to content

Instantly share code, notes, and snippets.

@ccnokes
Created August 11, 2017 20:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ccnokes/a79c3ee787d19309468f7e227b1b7732 to your computer and use it in GitHub Desktop.
Save ccnokes/a79c3ee787d19309468f7e227b1b7732 to your computer and use it in GitHub Desktop.
Rx.Observable.retry example
function randomErrorObs() {
return Rx.Observable.create(obs => {
let n = 0;
if(Math.random() < 0.5) {
obs.next(++n);
} else {
console.warn('producing error');
obs.error('bummer');
}
});
}
// retries 3 times, completes on the 4th failure
Rx.Observable.interval(300)
.switchMapTo(randomErrorObs())
.retry(3)
.subscribe(console.log, console.error, () => console.log('completed'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment