[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 ...
随机推荐
- && (and)、||(or) 条件语句
当前面条件满足时,就执行后面的代码 //条件为真时,就执行其中的语句 if($a>0){ $b='This is test'; } //上面的写法太麻烦,可以这样简写 $a>0 & ...
- 如何在一次请求中通过JS中获取Url中的参数
从A跳转到B,携带参数 例如: /pc/B.jsp?item=123456 B页面在js可以直接用 var item='${param.item}'; 这样就拿到啦 还有一种方法 定义一个函数 f ...
- There is no Action mapped for namespace [/] and action name [updateUser] associated with context path [].
在使用Struts2的时候,遇到了这个问题. 原因分析: 找不到指定的路径, 那么就是struts.xml的内容问题, 或者是struts.xml的文件位置存在问题. struts2默认是应该放在sr ...
- java生成随机字符
1.生成的字符串每个位置都有可能是str中的一个字母或数字,需要导入的包是import java.util.Random; //length用户要求产生字符串的长度 public static Str ...
- java对比IO和NIO的文件读写性能测试
1. NIO采用更接近操作系统执行IO的方式:通道和缓存器:顾名思义,数据源的数据由缓存器通过通道进行传输. 2. 在JDK5之后,原始IO系统底层用NIO进行了优化,这可以通过sun公布的源码中找到 ...
- [CF] 37 E. Trial for Chief
如果固定了一个中心,那么只需要考虑从它开始最远染到的那些点究竟染了几次. 上下左右不同的点连1边,相同的连0边,跑单源最短路就可以啦. lyd讲的是统计到最远黑点+1的最小值,但是#58数据全是白点, ...
- 从多表连接后的select count(*)看待SQL优化
从多表连接后的select count(*)看待SQL优化 一朋友问我,以下这SQL能直接改写成select count(*) from a吗? SELECT COUNT(*) FROM a LEFT ...
- (16) Cloudflare pki公钥基础设施
该工具组共有8个工具 1.cfssl 常用的可用指令: sign signs a certificate bundle build a certificate bundle genkey genera ...
- day16-python之函数式编程匿名函数
1.复习 #!/usr/bin/env python # -*- coding:utf-8 -*- name = 'alex' #name=‘lhf’ def change_name(): name= ...
- 大数据学习——hive数据类型
1. hive的数据类型Hive的内置数据类型可以分为两大类:(1).基础数据类型:(2).复杂数据类型2. hive基本数据类型基础数据类型包括:TINYINT,SMALLINT,INT,BIGIN ...