Created
March 23, 2018 11:53
-
-
Save nicowernli/835946a3f2c1a059c8616ca97cc072ac to your computer and use it in GitHub Desktop.
Medium 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 Rx = require('rxjs'); | |
const long$ = Rx.Observable.interval(1000).take(4); | |
const short$ = Rx.Observable.interval(500).take(4); | |
long$ | |
.switchMap(long => short$.map(short => console.log({ long, short }))) | |
.subscribe(); | |
/** Output | |
{ long: 0, short: 0 } | |
{ long: 1, short: 0 } | |
{ long: 2, short: 0 } | |
{ long: 3, short: 0 } | |
{ long: 3, short: 1 } | |
{ long: 3, short: 2 } | |
{ long: 3, short: 3 } | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment