[RxJS] Implement pause and resume feature correctly through RxJS
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
[RxJS] Implement pause and resume feature correctly through RxJS的更多相关文章
- [RxJS] Implement the `map` Operator from Scratch in RxJS
While it's great to use the RxJS built-in operators, it's also important to realize you now have the ...
- quartz2.3.0(五)制定错过执行任务的misfire策略,用pause,resume模拟job暂停执行和继续执行
感谢兄台: <quartz-misfire 错失.补偿执行> misfire定义 misfire:被错过的执行任务策略 misfire重现——CronTrigger job任务类: pac ...
- pause和resume
CCSet *m_pPausedTargets;类的成员变量 void CCNode::schedule(SEL_SCHEDULE selector, float interval, unsigned ...
- [RxJS] Implement RxJS `switchMap` by Canceling Inner Subscriptions as Values are Passed Through
switchMap is mergeMap that checks for an "inner" subscription. If the "inner" su ...
- [RxJS] Implement RxJS `mergeMap` through inner Observables to Subscribe and Pass Values Through
Understanding sources and subscribers makes it much easier to understand what's going on with mergeM ...
- [RxJS] Implement RxJS `concatMap` by Waiting for Inner Subscriptions to Complete
Unlike mergeMap and switchMap, concatMap focuses on when "inner" subscriptions "compl ...
- [RxJS] Aggregating Streams With Reduce And Scan using RxJS
What is the RxJS equivalent of Array reduce? What if I want to emit my reduced or aggregated value a ...
- [RxJS] Toggle A Stream On And Off With RxJS
This lesson covers how to toggle an observable on and off from another observable by showing how to ...
- [RxJS] Reactive Programming - Clear data while loading with RxJS startWith()
In currently implemention, there is one problem, when the page load and click refresh button, the us ...
随机推荐
- PHP foreach遍历数组之如何判断当前值已经是数组的最后一个
先给出foreach的两种语法格式 1,foreach (array_expression as $value) statement 2,foreach (array_expression as $k ...
- c#程序打包、机器代码生成(Ngen.exe)
深入本机影像生成器(Ngen.exe)工具使用方法详解 先介绍一点背景知识:.Net程序在运行时会实时(JIT)编译,将.Net程序文件编译成cpu认识的汇编机器码.实时编译需要消耗额外的cpu和内存 ...
- [React] Create a queue of Ajax requests with redux-observable and group the results.
With redux-observable, we have the power of RxJS at our disposal - this means tasks that would other ...
- 跟着辛星用PHP的反射机制来实现插件
我的博文的前一篇解说了PHP的反射机制是怎么回事,假设读者还不清楚反射机制,能够搜索下或者看我的博文,都是不错的选择.我们開始解说一下怎么用PHP来实现插件机制.所谓插件机制.就是我们定义一个接口.即 ...
- STM32介绍以及与通常ARM的区别
ARM是英国的芯片设计公司,其最成功的莫过于32位嵌入式CPU核----ARM系列,最常用的是ARM7和ARM9,ARM公司主要提供IP核,就是CPU的内核结构,只包括最核心的部分,并不是完整的处理器 ...
- Apache通用日志工具commons-logging和Log4j使用总结
转自:https://blog.csdn.net/lzl13391522110/article/details/53758536 Apache通用日志工具commons-logging和Log4j使用 ...
- MySQL乱码问题以及utf8mb4字符集---utf8mb4和utf8有什么区别? emoji表情与utf8mb4
utf8mb4兼容utf8,且比utf8能表示更多的字符. 关于emoji表情的话mysql的utf8是不支持,需要修改设置为utf8mb4,才能支持, 因为utf8mb4是utf8的超集
- RFID的工作流程
工作流程 1.阅读器通过发射天线发送一定频率的射频信号, 2.当射频卡进入发射天线工作区域时产生感应电流,射频卡获得能量被激活: 3.射频卡将自身编码等信息通过卡内置发送天线发送出去 4.系统接收天线 ...
- Java Servlet学习笔记(四)Servlet客户端Http请求
Servlet 客户端 HTTP 请求 当浏览器请求网页时,它会向 Web 服务器发送特定信息,这些信息不能被直接读取,因为这些信息是作为 HTTP 请求的头的一部分进行传输的.您可以查看 HTTP ...
- hibernate中的事务管理是怎么概念?
1.JDBC事务 JDBC 事务是用 Connection 对象控制的.JDBC Connection 接口( java.sql.Connection )提供了两种事务模式:自动提交和手工提交. ja ...