Last active
January 12, 2017 16:44
-
-
Save adrianmcli/c5bf2936fae44a45986b0dcf94a45458 to your computer and use it in GitHub Desktop.
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
/*** 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