Skip to content

Instantly share code, notes, and snippets.

@AndrewAllison
Created June 15, 2017 08:13
Show Gist options
  • Save AndrewAllison/e8035f5e35137b602a433bf5a7c67638 to your computer and use it in GitHub Desktop.
Save AndrewAllison/e8035f5e35137b602a433bf5a7c67638 to your computer and use it in GitHub Desktop.
RxJs for retrying to see if a value has changed over a period
const state = Observable.timer(1000) // every second
.map(() => this.loaded)
.repeat(8) // retry 8 times
.retry();
state.subscribe((res) => {
// this is the main body of the retry
console.log('Result: ', res) // will out put false 8 times for the loaded value.
}, (err) => { }, () => {
if (this.loaded === false) {
this.errorLoading = true; // If it hasn't loaded in 8 secs it ain't gonna ;)
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment