Skip to content

Instantly share code, notes, and snippets.

@adrianmcli
Last active January 12, 2017 16:44
Show Gist options
  • Save adrianmcli/c5bf2936fae44a45986b0dcf94a45458 to your computer and use it in GitHub Desktop.
Save adrianmcli/c5bf2936fae44a45986b0dcf94a45458 to your computer and use it in GitHub Desktop.
/*** Hot Stream ***/
// there is only "one real" invocation of the stream
const count$ = Rx.Observable.interval(1000).share();
count$.subscribe(x => console.log('A' + x));
setTimeout(() => {
count$.subscribe(x => console.log(' B' + x));
}, 2000);
// Output:
// -------
// sub A: 0--1--2--3--4--5-->
// sub B: ------2--3--4--5-->
/*** Cold Stream ***/
// each subscriber gets their own invocation
const count$ = Rx.Observable.interval(1000)
count$.subscribe(x => console.log('A' + x))
setTimeout(() => {
count$.subscribe(x => console.log(' B' + x))
}, 2000);
// Output:
// -------
// sub A: 0--1--2--3--4--5-->
// sub B: ------0--1--2--3-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment