Skip to content

Instantly share code, notes, and snippets.

@sergzak022
Created January 18, 2018 21:40
Show Gist options
  • Save sergzak022/b0d92f482fa95dcd8ac61270a1a37c03 to your computer and use it in GitHub Desktop.
Save sergzak022/b0d92f482fa95dcd8ac61270a1a37c03 to your computer and use it in GitHub Desktop.
RxJS: Switching and Exhausting
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