Last active
April 1, 2019 00:01
-
-
Save kosich/c14c6642424e485de51ab1c8c2d979be to your computer and use it in GitHub Desktop.
Switch sources on timeout
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 { chart } = require('rp-api'); | |
const { from, timer } = require('rxjs'); | |
const { delayWhen, share, map, timeout, catchError, repeat, take } = require('rxjs/operators'); | |
const source$ = from([ 5, 20, 25, 30, 42, 45 ]) | |
.pipe( | |
delayWhen(timer) | |
, share() | |
); | |
const timer$ = timer(0, 5) | |
.pipe( | |
map(x => 't:' + x) | |
, share() | |
); | |
const output$ = source$ | |
.pipe( | |
timeout(2) | |
, catchError(()=> | |
timer$ | |
.takeUntil(source$) | |
.merge(source$.take(1)) | |
) | |
, repeat() | |
, take(10) | |
); | |
timer$.take(10).subscribe(chart.createRxObserver()); | |
source$.subscribe(chart.createRxObserver()); | |
output$.subscribe(chart.createRxObserver()); |
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/c14c6642424e485de51ab1c8c2d979be