Last active
August 16, 2018 13:05
-
-
Save obenjiro/345ba0b785a663bd6b433dbbac07f279 to your computer and use it in GitHub Desktop.
Naive of cancelable switchMap
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 { interval, of, from, pipe, empty } = Rx; | |
const { take, tap, share, takeUntil, switchMap,startWith, withLatestFrom, filter, concatMap, delay, merge } = RxOperators; | |
const $refresh = interval(1000).pipe( | |
take(4), | |
concatMap((x) => of(x).pipe(delay(x <= 2 ? 2000 : 1000))), | |
share() | |
) | |
const cancel$ = of(-1).pipe(delay(5200), share()); | |
$refresh.pipe( | |
switchMap((r) => of(r).pipe( | |
delay(1800), | |
takeUntil(cancel$) | |
)) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment