[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 ...
随机推荐
- 制作JPEGImages出现的bug
我用的是下面这个脚本进行改名字: import os import sys path = "/home/bnrc/py-faster-rcnn/data/VOCdevkit2007/VOC2 ...
- Spring-01 注解实现IOC
Spring框架四大原则 使用pojo进行轻量级和最小侵入式开发. 通过依赖注入和基于接口编程实现松耦合. 使用AOP和默认习惯进行声明式编程. 使用AOP和模板(template)减少模式化代码. ...
- [LUOGU] P1962 斐波那契数列
求斐波那契第n项. [f(n-1) f(n)] * [0,1] = [f(n) f(n+1)] [1,1] 由此原理,根据矩阵乘法的结合律,用快速幂算出中间那个矩阵的n次方即可. 快速幂本质和普通快速 ...
- 深入理解JavaScript的设计模式
使用适当的设计模式可以帮助你编写更好.更易于理解的代码.这样的代码也更容易维护.但是,重要的是不要过度使用它们.在使用设计模式之前,你应该仔细考虑你的问题是否符合设计模式. 当你开始一个新的项目时,你 ...
- Python之微信-微信好友头像合成
仔细看下图,你的头像就藏在里面哦!!! 有没有犯密集恐惧症?这并不震撼,如果你有 5000 位好友的话,做出来的图看着会更刺激些. 看完了图,你可能想知道这个图咋做出来的,不会是我闲着无聊把把好友头像 ...
- pwnable.kr cmd1之write up
看一下源代码: #include <stdio.h> #include <string.h> int filter(char* cmd){ ; r += strstr(cmd, ...
- Python中的*arg和**kwarg
一个简单的函数 首先我们可以定一个简单的函数, 函数内部只考虑required_arg这一个形参(位置参数) def exmaple(required_arg): print required_arg ...
- 在C#代码中应用Log4Net系列教程(附源代码)地址
在博客园看到一篇关于Log4Net使用教程,比较详细,感谢这位热心的博主 博客园地址:http://www.cnblogs.com/kissazi2/archive/2013/10/29/339359 ...
- JS Enter键跳转 控件获得焦点
//回车跳转 jQuery(document).ready(function () { //$(':input:text:first').focus(); jQuery(':input:enabled ...
- OSPF选路原则
1:O路由>Oia路由>external路由! O:计算LSA-1和LSA-2,前提age不能MaxAge,metric不能LSinfinity,计算出来的最小metric的路由放入RIB ...