官方链接:https://rxjs-dev.firebaseapp.com/api/index/function/merge

Creates an output Observable which concurrently emits all values from every given input Observable.

创建一个输出 Observable,它同时发出来自每个给定输入 Observable 的所有值。

merge subscribes to each given input Observable (as arguments), and simply forwards (without doing any transformation) all the values from all the input Observables to the output Observable. The output Observable only completes once all input Observables have completed. Any error delivered by an input Observable will be immediately emitted on the output Observable.

merge 订阅每个给定的输入 Observable(作为参数),并简单地将所有输入 Observable 的所有值(不做任何转换)转发到输出 Observable。 输出 Observable 仅在所有输入 Observable 完成后才完成。 输入 Observable 传递的任何错误都将立即在输出 Observable 上发出。

看一个例子:

import { merge, fromEvent, interval } from 'rxjs';const clicks = fromEvent(document, 'click');
const timer = interval(1000);
const clicksOrTimer = merge(clicks, timer);
clicksOrTimer.subscribe(x => console.log(x));

输出:

另一个例子:

import { merge, interval } from 'rxjs';
import { take } from 'rxjs/operators';const timer1 = interval(1000).pipe(take(10));
const timer2 = interval(2000).pipe(take(6));
const timer3 = interval(500).pipe(take(10));
const concurrent = 2; // the argument
const merged = merge(timer1, timer2, timer3, concurrent);
merged.subscribe(x => console.log(x));// Results in the following:
// - First timer1 and timer2 will run concurrently
// - timer1 will emit a value every 1000ms for 10 iterations
// - timer2 will emit a value every 2000ms for 6 iterations
// - after timer1 hits its max iteration, timer2 will
//   continue, and timer3 will start to run concurrently with timer2
// - when timer2 hits its max iteration it terminates, and
//   timer3 will continue to emit a value every 500ms until it is complete

输出:

更多Jerry的原创文章,尽在:“汪子熙”:

Rxjs merge 学习笔记相关推荐

  1. RxJs SwitchMap 学习笔记

    网址:https://www.learnrxjs.io/learn-rxjs/operators/transformation/switchmap The main difference betwee ...

  2. RxJS mergeMap 学习笔记

    https://www.learnrxjs.io/learn-rxjs/operators/transformation/mergemap This operator is best used whe ...

  3. rxjs operator学习笔记

    Pipeable Operators are the kind that can be piped to Observables using the syntax observableInstance ...

  4. Pro Android学习笔记(二九):用户界面和控制(17):include和merge

    xml控件代码重用:include 如果我们定义一个控件,需要在不同的layout中重复使用,或者在同一个layout中重复使用,可以采用include的方式.例如定义my_button.xml如下 ...

  5. 【转】 Pro Android学习笔记(二九):用户界面和控制(17):include和merge

    目录(?)[-] xml控件代码重用include xml控件代码重用merge 横屏和竖屏landsacpe portrait xml控件代码重用:include 如果我们定义一个控件,需要在不同的 ...

  6. OpenCV学习笔记(三):多通道图像分离、混合算子:split(),merge()

    OpenCV学习笔记(三):多通道图像分离.混合算子:split(),merge() #include <opencv2/opencv.hpp>#define BRG_BLUE_CHANN ...

  7. Python学习笔记---merge和concat数据合并(1)

    Python学习笔记-merge和concat数据合并(1) Python学习笔记-merge和concat数据合并(2) 文章目录 Python学习笔记---merge和concat数据合并(1) ...

  8. 【学习笔记】线性代数全家桶(在编程竞赛中的应用)

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 0x00. 矩阵 0x01. 矩阵 0x02. 矩阵的加法与数量乘法 0x03. 矩阵乘法 0x ...

  9. SQL Server 2008/2012中SQL应用系列及BI学习笔记系列--目录索引

    SQL Server 2008中的一些特性总结及BI学习笔记系列,欢迎与邀月交流. 3w@live.cn  ◆0.SQL应用系列 1.SQL Server 2008中SQL增强之一:Values新用途 ...

最新文章

  1. 数据库分库分表(sharding)系列
  2. 关于动态生成输入界面的一些想法及实践
  3. 裸眼 3D 是什么效果?
  4. flask对mysql数据库增删改查_flask后台框架1.4(mysql配置+数据库增删改查)-Go语言中文社区...
  5. 图像局部特征(三)--FAST角点检测子
  6. 电力系统建模与仿真, 地理接线图,配电图,电力系统组态与监控,电力调度,自动控制,VBScript脚本控制,JavaScript脚本控制, 潮流分析2018...
  7. 开关三极管的导通和截止条件
  8. 《pr2019》怎么加字幕
  9. jetbrains DataGrip 1.0注册破解方法
  10. 【HTML】Canvas(3)-绘制图片
  11. [矩阵求逆+二分图匹配]BZOJ 3168 [Heoi2013]钙铁锌硒维生素
  12. 布雷默曼极限 (Bremermann‘s limit)
  13. 法国队夺了世界杯冠军,却彻底打了AI预测的脸
  14. 带音效的计算机软件,音效增强软件哪个好用?好用的音效增强软件推荐
  15. IOS大牛的技术人生的经验与心得
  16. 宣布全面开源,微众银行正下一盘区块链商业的大棋
  17. Houdini中四种实现龙卷风速度场的方法及比较
  18. 为什么需要选择服务器托管?
  19. 【PC工具】HiPC手机远程控制电脑软件,微信小程序远程控制电脑
  20. app直播源代码是如何实现直播间小游戏的

热门文章

  1. 路飞学城-python爬虫密训-第三章
  2. ***解决UEditor编辑器无法插入第三方视频地址
  3. 使用的postman心得
  4. 网银安全恐慌“后遗症”凸显 肉鸡检测器下载量近百万
  5. 到国外使用wifi悠着点防止天价帐单
  6. 实用教程 活动目录介绍及安装指南
  7. 使用母版頁是內容如何使用CSS和javascript(轉)
  8. 从零写一个编译器(十二):代码生成之生成逻辑
  9. MySQL异步复制延迟解决的架构设计与运维架构ppt
  10. 基于python的request库,模拟登录csdn博客