Making a stream hot

This hotStream$, how can it be created? You did say that most of the streams being created are cold? We have an operator for doing just that, or two operators, in reality. We can make a stream go from cold to hot by using the operators publish() and connect(). Let's start with a cold Observable and add the mentioned operators, like so:

// hot-cold-warm/hot-observable.jsconst Rx = require("rxjs/Rx");let start = new Date();let stream = Rx.Observable  .interval(1000)  .take(5)  .publish();setTimeout(() => {  stream.subscribe(data => {    console.log(`subscriber 1 ${new Date() - start}`, data);  });}, 2000);setTimeout(() => {  stream.subscribe(data => {    console.log(`subscriber 2 ${new Date() - start}`, data)  });}, 3000);stream.connect ...

Get Architecting Angular Applications with Redux, RxJS, and NgRx now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.