Last active
March 17, 2019 17:33
-
-
Save kosich/c526cd7d75713adbf86b60db5860e333 to your computer and use it in GitHub Desktop.
Wait source for no more then 20ms, if it fails -- retry 3 times. Example for https://stackoverflow.com/questions/55206845/rxjs-wait-on-value-from-observable-if-it-doesnt-come-after-a-specified-time-p
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
const { rxObserver, palette } = require('api/v0.3'); | |
const { of, timer } = require('rxjs'); | |
const { retry, switchMap, timeout } = require('rxjs/operators'); | |
let index = 0; | |
const source$ = of(void 0).pipe( | |
switchMap(()=> | |
// 4 attempts | |
timer([20, 20, 20, 5][index++]) | |
) | |
); | |
const retry$ = source$.pipe( | |
timeout(10), | |
retry(3) | |
); | |
retry$.subscribe(rxObserver()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run at https://observable-playground.github.io/gist/c526cd7d75713adbf86b60db5860e333