Unlike mergeMap and switchMapconcatMap 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的更多相关文章

  1. [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 ...

  2. [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 ...

  3. eclipse the user operation is waiting for building workspace" to complete

    "the user operation is waiting for building workspace" to complete", 解决办法: 1.选择菜单栏的“P ...

  4. SHUTDOWN: waiting for active calls to complete

    Problem Description: ====================  You are attempting to shut down the database and the data ...

  5. 关闭数据库时SHUTDOWN: waiting for active calls to complete.处理

    有时候在关闭数据库时,发出shutdown immediate;命令后一直未关闭.查看ALERT日志.在等待一段时间后日志中有提示: SHUTDOWN: waiting for active call ...

  6. [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 ...

  7. [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 ...

  8. [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 ...

  9. [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 ...

随机推荐

  1. && (and)、||(or) 条件语句

    当前面条件满足时,就执行后面的代码 //条件为真时,就执行其中的语句 if($a>0){ $b='This is test'; } //上面的写法太麻烦,可以这样简写 $a>0 & ...

  2. 如何在一次请求中通过JS中获取Url中的参数

    从A跳转到B,携带参数 例如: /pc/B.jsp?item=123456 B页面在js可以直接用 var item='${param.item}'; 这样就拿到啦 还有一种方法 定义一个函数   f ...

  3. There is no Action mapped for namespace [/] and action name [updateUser] associated with context path [].

    在使用Struts2的时候,遇到了这个问题. 原因分析: 找不到指定的路径, 那么就是struts.xml的内容问题, 或者是struts.xml的文件位置存在问题. struts2默认是应该放在sr ...

  4. java生成随机字符

    1.生成的字符串每个位置都有可能是str中的一个字母或数字,需要导入的包是import java.util.Random; //length用户要求产生字符串的长度 public static Str ...

  5. java对比IO和NIO的文件读写性能测试

    1. NIO采用更接近操作系统执行IO的方式:通道和缓存器:顾名思义,数据源的数据由缓存器通过通道进行传输. 2. 在JDK5之后,原始IO系统底层用NIO进行了优化,这可以通过sun公布的源码中找到 ...

  6. [CF] 37 E. Trial for Chief

    如果固定了一个中心,那么只需要考虑从它开始最远染到的那些点究竟染了几次. 上下左右不同的点连1边,相同的连0边,跑单源最短路就可以啦. lyd讲的是统计到最远黑点+1的最小值,但是#58数据全是白点, ...

  7. 从多表连接后的select count(*)看待SQL优化

    从多表连接后的select count(*)看待SQL优化 一朋友问我,以下这SQL能直接改写成select count(*) from a吗? SELECT COUNT(*) FROM a LEFT ...

  8. (16) Cloudflare pki公钥基础设施

    该工具组共有8个工具 1.cfssl 常用的可用指令: sign signs a certificate bundle build a certificate bundle genkey genera ...

  9. day16-python之函数式编程匿名函数

    1.复习 #!/usr/bin/env python # -*- coding:utf-8 -*- name = 'alex' #name=‘lhf’ def change_name(): name= ...

  10. 大数据学习——hive数据类型

    1. hive的数据类型Hive的内置数据类型可以分为两大类:(1).基础数据类型:(2).复杂数据类型2. hive基本数据类型基础数据类型包括:TINYINT,SMALLINT,INT,BIGIN ...