Created
June 15, 2017 08:13
-
-
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
This file contains hidden or 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
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