Last active
December 17, 2020 00:52
-
-
Save ben-barbier/65cadda8571ac06a7fff8d6712678fd5 to your computer and use it in GitHub Desktop.
⚡️RxJS 🚀, mergemap with retry and fallback
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
public launchCachePreloading() { | |
this.nomenclatureService.getUniverses().pipe( | |
flatMap(e => e), | |
mergeMap(universe => this.nomenclatureService.getFamilies(universe.id).pipe( | |
flatMap(e => e), | |
map(family => ({universeId: universe.id, familyId: family.id})), | |
)), | |
toArray(), | |
mergeMap(families => interval(1000).pipe( | |
filter(() => this.router.url === '/'), | |
take(families.length), | |
scan((acc) => acc + 1, -1), | |
map(idx => families[idx]), | |
mergeMap((e) => of(e).pipe( | |
mergeMap(() => this.nomenclatureService.getProducts(e.universeId, e.familyId)), | |
retry(2), | |
catchError(() => EMPTY), | |
)), | |
)) | |
).subscribe(e => { | |
console.log('val: ' + JSON.stringify(e)); | |
}, err => { | |
console.log('err: ' + err); | |
}, () => { | |
console.log('finish !!!'); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment