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 小记 整数与小数id

    上图,id A =B id 1.0  c != d 以后少用 带小数后位的数字.调用内存地址不一样

  2. info.plist 属性讲解

    1 常用项: Application requires iPhone environment:如果应用程序不能在ipodtouch上运行,设置此项为true; Application usesWi-F ...

  3. c# 测试

    string input = "//a/@href "; int index = input.IndexOf("/@"); String attr = inpu ...

  4. 全球顶级专家为你解读:什么是真正的 DevOps?

    [编者按]本文是 Skytap 内容主编 Noel Wurst 对 DevOps Enterprise Summit (DOES)的不完全综述,内容包括了 Noel 和一些与会嘉宾的思考,旨在勾画 D ...

  5. WIN10 + VS2015 + WDK10 + SDK10 + VM虚拟机驱动开发调试环境搭建

    http://blog.csdn.net/qing666888/article/details/50858272#comments

  6. lc面试准备:Reverse Bits

    1 题目 Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represente ...

  7. [cocos2d demo]新科娘收集水表

    讲述的是新科娘在沙滩上遇到一大波水表的故事... 下载地址 链接:http://pan.baidu.com/share/link?shareid=2141087190&uk=293716439 ...

  8. Server.Transfer方法,Server.Execute方法和Response.Redirect方法有什么异同

    (1)Server.Transfer方法: Server.Transfer("m2.aspx");//页面转向(服务器上执行). 服务器停止解析本页,保存此页转向前的数据后,再使页 ...

  9. linux配置Java(JDK)环境变量

    本帖最后由 zhai 于 2013-11-19 23:00 编辑 1.下载jdk Oracle官方下载地址:http://www.oracle.com/technetwork/java/javase/ ...

  10. Delphi 编写的Web Service

      一编写服务程序 第一步:File----->New----->Other------>WebServices----->Soap Server Application选择I ...