Skip to content

Instantly share code, notes, and snippets.

@zachgoll
Last active September 13, 2020 16:58
Show Gist options
  • Save zachgoll/b803040051ead93eaa66ccf384188b90 to your computer and use it in GitHub Desktop.
Save zachgoll/b803040051ead93eaa66ccf384188b90 to your computer and use it in GitHub Desktop.
const { interval, Observable } = Rx;
const { map, take, switchMap, startWith, mergeMapTo } = RxOperators;
function outerObservable() {
return new Observable(subscriber => {
setTimeout(() => {
subscriber.next("A");
}, 1000);
setTimeout(() => {
subscriber.next("C");
}, 1500);
setTimeout(() => {
subscriber.next("B");
subscriber.complete();
}, 4000);
})
}
// Emit the value 10 every second
function innerObservable() {
return interval(1000).pipe(map(val => val + 1),take(3));
}
outerObservable().pipe(
mergeMapTo(
innerObservable(),
(x, y) => x + y
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment