Created
January 18, 2018 21:40
-
-
Save sergzak022/b0d92f482fa95dcd8ac61270a1a37c03 to your computer and use it in GitHub Desktop.
RxJS: Switching and Exhausting
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
var source$ = Observable.timer(0, 200).take(6); | |
function multBy2Delayed(number) { | |
// I take 1000ms to multiply your number by two | |
return Observable.timer(1000).map(() => number * 2); | |
} | |
// NEW CODE STARTS HERE | |
var switched$ = source$.switchMap((number) => { | |
return multBy2Delayed(number); | |
}); | |
switched$.subscribe((number) => { | |
console.log(number); // will log 10 to console | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment