Eventually you will feel the need for pausing the observation of an Observable and resuming it later. In this lesson we will learn about use cases where pausing is possible, and what to do when pausing is impossible.

const resume$ = new Rx.Subject();

const res$ = resume$
.switchMap(resume =>
resume ?
Rx.Observable.interval() :
Rx.Observable.empty()
)
.do(x => console.log('request it! ' + x))
.switchMap(ev => Rx.Observable.ajax({
url: 'https://jsonplaceholder.typicode.com/users/1',
method: 'GET',
})); res$.subscribe(function (data) {
console.log(data.response);
}); resume$.next(false);
setTimeout(() => resume$.next(true), );
setTimeout(() => resume$.next(false), );

here use

Rx.Observable.empty()

inside switchMap(), it means if code goes to empty(), then the rest of code:

 .do().switchMap()

won't run.

If just subscribe, it trigger complete function:

var source = Rx.Observable.empty();

var subscription = source.subscribe(
function (x) {
console.log('Next: %s', x);
},
function (err) {
console.log('Error: %s', err);
},
function () {
console.log('Completed');
}); // => Completed

最新文章

  1. C#获取图片的后缀名
  2. 深入ThreadLocal之一
  3. Mac OS X操作系统常见快捷键集锦
  4. java新手笔记34 连接数据库
  5. POJ 2728 Desert King ★(01分数规划介绍 && 应用の最优比率生成树)
  6. bzoj1040
  7. Spring的多配置文件加载
  8. 文件上传工具swfupload[转]
  9. [PWA] 11. Serve skeleton cache for root
  10. 真正的手机破解wifi密码,aircrack-ng,reaver,仅限mx2(BCM4330芯片)
  11. 正则表达式引擎的构建——基于编译原理DFA(龙书第三章)——3 计算4个函数
  12. 想在网上保持匿名?教你用Linux如何实现!
  13. iOS .tbd
  14. 匿名内部类可以访问的变量---静态成员变量和final修饰的局部变量
  15. android学习十二(android的Content Provider(内容提供器)的使用)
  16. Scrapy框架基本使用
  17. 用nodejs搭建一个简单的服务监听程序
  18. Bitnami Redmine 中文附件名 报错修复
  19. VS2017中建立ASP.NET MVC 4.0项目
  20. [Jenkins] 批量删除构建历史

热门文章

  1. LuoguP3254 圆桌问题(最大流)
  2. VMware Vsphere 6.0安装部署 vCenter Server安装
  3. logrotate---日志分割
  4. 微信小程序从零开始开发步骤(七)引入外部js 文件
  5. 【Henu ACM Round #12 D】 Longest Subsequence
  6. Dubbo学习总结(4)——Dubbo基于Zookeeper实现分布式实例
  7. Vijos——T 1164曹冲养猪
  8. Activity Test1
  9. 2.写给设计师看的HTML&CSS入门指导
  10. js原生代码实现鼠标拖拽(超简单)