Single, race both get only one emit value from the stream.

Single(fn):

const source = Rx.Observable.from([1,2,3,4,5]);
var single = source.single( x => x === 3); /* (12345)| (source) single( x => x === 3)
3| (single) */ var sub = single.subscribe( x => console.log(x)); //

race(...observable): Observable

const winner = Rx.Observable.race(
//emit every 1.5s
Rx.Observable.interval(1500),
//emit every 1s
Rx.Observable.interval(1000).mapTo('1s won!'),
//emit every 2s
Rx.Observable.interval(2000),
//emit every 2.5s
Rx.Observable.interval(2500)
).take(1); /** ------0 (1500)
----0 (1000).mapTo('1s won!')
--------0 (2000)
----------0 (2500) race ----(1s won!)| (take(1)) */ const sub2 = winner.subscribe( x => console.log(x)); // 1s won!

[RxJS] Filtering operator: single, race的更多相关文章

  1. [RxJS] Filtering operator: filter

    This lesson introduces filter: an operator that allows us to let only certain events pass, while ign ...

  2. [RxJS] Filtering operators: distinct and distinctUntilChanged

    Operator distinct() and its variants are an important type of Filtering operator. This lessons shows ...

  3. rxjs自定义operator

    rxjs自定义operator

  4. [RxJS] Utility operator: do

    We just saw map which is a transformation operator. There are a couple of categories of operators, s ...

  5. [RxJS] Creation operator: of()

    RxJS is a lot about the so-called "operators". We will learn most of the important operato ...

  6. [RxJS] Connection operator: multicast and connect

    We have seen how Subjects are useful for sharing an execution of an RxJS observable to multiple obse ...

  7. [rxjs] Shares a single subscription -- publish()

    If have an observable and you subscribe it twice, those tow subscritions have no connection. console ...

  8. [RxJS] Transformation operator: repeat

    Operator repeat() is somewhat similar to retry(), but is not for handling operators. In this lesson ...

  9. [RxJS] Filtering operators: throttle and throttleTime

    Debounce is known to be a rate-limiting operator, but it's not the only one. This lessons introduces ...

随机推荐

  1. Python深入学习笔记(二)

    计数器Counter Counter类是自Python2.7起增加的,属于字典类的子类,是一个容器对象,主要用来统计散列对象,支持集合操作+.-.&.|,其中后两项分别返回两个Counter对 ...

  2. OOS升级服务

    给我们的应用程序做个版本更新服务,展示一个安装程序如何实现自动更新. //服务组,添加需要的任何服务 public enum ServerEnum { AutoupdateService,//自动升级 ...

  3. 从文章"避免复制与粘贴"到文章"Extract Method"的反思(1)

    看了一个比我牛的人的博客园的博文"避免复制和粘贴".里面提到了重构手法Extract Method.  所以又搜了一下Extract Method. 这里先自我理解Extract ...

  4. eclipse/myeclipse选中编辑区域文件,Package Explorer定位文件所在项目及目录

    eclipse/myeclipse选中编辑区域文件,Package Explorer定位文件所在项目及目录 1. 打开Package Explorer(若没有,可以按照如下路径点击: Window菜单 ...

  5. Java客户端协议处理框架简介

    无论FTP客户程序,还是HTTP客户程序,或是其他基于特定应用层协议的客户程序,在与远程服务器通信时,都需要建立与远程服务器的连接,然后发送和接收与协议相符的数据.客户程序还需要对服务器发送的数据进行 ...

  6. 10个WordPress增强型编辑器大检阅

    Wordpress之所以优秀不在于其本身,而在于无数的插件开发者和性能优化人员.使用过Wordpress的人都知道,WP本身的编辑器极其简陋,就连简单的表格编辑也没有,可能吧这篇文章将介绍一些免费的增 ...

  7. 在debug模式下运行不报错,换到release模式下报找不到某某库或文件的错。。解决办法

    我遇到的问题是:把edit secheme调到debug模式运行没有问题,然后调到release模式的时候报目录下没有libTuyoo.a 解决办法 把断开真机设备,用IOS device下relea ...

  8. 教你把UIView切成任意形状

    有时候layer.cornerRadius并不能满足需求,自己实现drawRect又太麻烦,怎么办? 多的不说,直接上代码: - (void)dwMakeBottomRoundCornerWithRa ...

  9. Linux启动或禁止SSH用户及IP的登录

    启动或禁止SSH用户登录 一般情况下,在使用Linux操作系统都不会去机房来操作机器,都是使用一些第三方的工具来操作. 比如使用SSH Secure File Transfer Client工具来传输 ...

  10. bzoj2743

    其实和bzoj1878类似只不过要求的是区间内数量多于1个的数字种数其实还是按照bzoj1878做只不过我们是把每一种数字下一个出现的位置+1,并把这个位置置为0 ..] of longint; ma ...