[RxJS] Implement RxJS `concatMap` by Waiting for Inner Subscriptions to Complete
Unlike mergeMap and switchMap, concatMap focuses on when "inner" subscriptions "complete" by using a "buffer". Each time concatMap receives a value, it adds each value to a "buffer", waits for previous "inner" subscription to complete, then invokes next with the next value from the "buffer".
class MyConcatMapSubscriber extends Subscriber {
innerSubscription;
buffer = [];
constructor(sub, fn) {
super(sub);
this.fn = fn;
}
_next(value) {
const { isStopped } = this.innerSubscription || {
isStopped: true
};
if (!isStopped) {
this.buffer = [...this.buffer, value];
} else {
const o$ = this.fn(value);
this.innerSubscription = o$.subscribe({
next: value => {
this.destination.next(value);
},
complete: () => {
if (this.buffer.length) {
const { first, ...rest } = this.buffer;
this.buffer = rest;
this._next(first);
}
}
});
}
}
}
[RxJS] Implement RxJS `concatMap` by Waiting for Inner Subscriptions to Complete的更多相关文章
- [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 ...
- eclipse the user operation is waiting for building workspace" to complete
"the user operation is waiting for building workspace" to complete", 解决办法: 1.选择菜单栏的“P ...
- SHUTDOWN: waiting for active calls to complete
Problem Description: ==================== You are attempting to shut down the database and the data ...
- 关闭数据库时SHUTDOWN: waiting for active calls to complete.处理
有时候在关闭数据库时,发出shutdown immediate;命令后一直未关闭.查看ALERT日志.在等待一段时间后日志中有提示: SHUTDOWN: waiting for active call ...
- [RxJS] Use RxJS concatMap to map and concat high order observables
Like switchMap and mergeMap, concatMap is a shortcut for map() followed by a concatAll(). In this le ...
- [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 ...
- [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 ...
- [RxJS] Chain RxJS Operators Together with a Custom `pipe` Function using Array.reduce
Instead of writing complex operators, it's usually best to write simple, single-purpose operators th ...
随机推荐
- DP || HYSBZ 1207 打鼹鼠
n*n的网格,有m个鼹鼠,t时间会有一只鼹鼠出现在(x,y)点处,如果机器人也在这个点就可以打到鼹鼠 机器人初始位置任意,每秒可以移动一格,问最多打到多少鼹鼠 *解法:f[i]表示前i只鼹鼠打了多少个 ...
- python之道02
猜数字,设定一个理想数字比如:66,让用户输入数字,如果比66大,则显示猜测的结果大了,然后继续让用户输入; 如果比66小,则显示猜测的结果小了,然后继续让用户输入;只有等于66,显示猜测结果正确,然 ...
- MySQL-01 MySQL数据库安装指南
学习要点 MySQL数据库的安装和设置 下载mysql mysql官网:https://www.mysql.com/downloads/ 主要版本: Oracle MySQL Cloud Servic ...
- 第4节 hive调优:2、数据倾斜
数据的倾斜: 主要就是合理的控制我们的map个数以及reduce个数 第一个问题:maptask的个数怎么定的???与我们文件的block块相关,默认一个block块就是对应一个maptask 第二个 ...
- VR技术在数据中心3D机房中的应用(上)
VR技术在数据中心3D机房中的应用(上) 前两天跟朋友A吃饭,吃着吃着就说到了VR.近几年来,VR技术越来越火,感觉能跟VR沾点边的都特别高大上,朋友A也是,一提到VR,就怎么都掩盖不住他发自肺腑 ...
- Fortran中常用函数列表
Y=INT(X) 转换为整数 ALL(所有型态) INTEGER Y=REAL(X) 转换为实数 INTEGER REAL Y=DREAL(X) 取复数实部(倍精度) COMPLEX*16 REAL* ...
- tcpdump抓包指令使用示例
tcpdump是一个用于截取网络分组,并输出分组内容的工具. tcpdump凭借强大的功能和灵活的截取策略,使其成为类UNIX系统下用于网络分析和问题排查的首选工具.tcpdump提供了源代码,公开了 ...
- php函数之数组
关联数组 isset bool isset( mixed $val [, mix $...]) 变量是否已设置并且非null.多个参数从左到右计算. 判断null $a=null;var_dump(i ...
- HTML5结构
1.显示编排内容区域块(明确使用section等元素创建文档结构,在每个区域块中使用标题元素) 2.隐示编排内容区域块(不明确使用section等元素,而是根据网页需求来将各级的元素创建出来) 3.标 ...
- MySQL数据类型与操作
内容提要: 建表完整语法规范(create table 表格(字段名1 类型 (宽度) 约束条件)) MySQL数据库数据类型(整型.浮点型.字符类型(char与varchar).日期类型.枚举与集合 ...