Cold:

console.clear();
var Observable = Rx.Observable;
var clock = Observable.interval(1000).take(10).map((i) => `${i}!`);
clock.subscribe((x) => {
console.log(` a ${x}`);
}); setTimeout(function(){
clock.subscribe((x) => {
console.log(` b ${x}`);
});
}, 3500);

Results:

/*
" a 0!"
" a 1!"
" a 2!"
" a 3!"
" b 0!"
" a 4!"
" b 1!"
" a 5!"
" b 2!"
" a 6!"
" b 3!"
" a 7!"
" b 4!"
" a 8!"
" b 5!"
" a 9!"
" b 6!"
" b 7!"
" b 8!"
" b 9!"
*/

As you can see, 'a' and 'b' all start from '0'. They are independent. As youtube vedio, you can open the same vedio in tow tabs. When you click play, those two vedio will play independently.

Hot: publish().refCount();

Hot Observables are like 'live' youtube video, everyone watch the same vedio at the same pace.

As I wrote in previous article about publish(); you can use this with connect() funciton, but there is problem, we will miss the very first event.

RefCount and a hot observable is analogous to a live video of a band playing at a concert, but the band doesn't start playing if there isn't anyone in the audience. That would be a waste, right? So, why play if there is no one watching?

RefCount tells the band to play when there is at least one person in the audience, in other words, when the number of observers goes from zero to one.

console.clear();
var Observable = Rx.Observable;
var clock = Observable.interval(1000).take(10).map((i) => `${i}!`).publish().refCount();
clock.subscribe((x) => {
console.log(` a ${x}`);
}); setTimeout(function(){
clock.subscribe((x) => {
console.log(` b ${x}`);
});
}, 3500);

Results:

/*" a  0!"
" a 1!"
" a 2!"
" a 3!"
" b 3!"
" a 4!"
" b 4!"
" a 5!"
" b 5!"
" a 6!"
" b 6!"
" a 7!"
" b 7!"
" a 8!"
" b 8!"
" a 9!"
" b 9!"
*/

最新文章

  1. Mobile Safari调用本地App, 否则进入App Store下载
  2. 《你必须知道的.NET》读书笔记:从Hello World认识IL
  3. MyEclispe 2015 CI 15发布(附下载)
  4. Struts2应用流程注解
  5. pb数据窗口设置操作
  6. YUSE_DOWN-批下载
  7. mysql 索引 详解
  8. angularJS自定义指令间的“沟通”
  9. PostgreSQL没有redo log multiplexing
  10. Android 自定义View修炼-如何打造Android自定义的下拉列表框控件
  11. codeforces 610B
  12. 【C#、csharp】HTTPGET,POST请求
  13. Linux期中架构
  14. W3bsafe]SQLmap过狗命令的利用+教程
  15. docker学习笔记(四)-持久化数据,安装docker-compose
  16. 前台ajax传参数,后台spring mvc用对象接受
  17. Windows Server 2016 启用完整版任务管理器
  18. hbase源码系列(十)HLog与日志恢复
  19. eclipse format xml
  20. 如何删除word中多余的空格和空行

热门文章

  1. Redis总录
  2. Swift开发之 ---- Swift宏定义
  3. bzoj 3242: [Noi2013]快餐店 章鱼图
  4. Spring 使用外部部署文件
  5. JAVA 内存泄漏与内存溢出
  6. JavaScript元素的创建、添加、删除
  7. 如何实现Azure虚拟网络中点到站VPN的自动重连
  8. JW Player 现在支持 Azure 媒体服务
  9. 动态规划(DP计数):HDU 5117 Fluorescent
  10. PHPcurl抓取AJAX异步内容(转载)