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. frameset标签代码实现网站跳转

    js代码1: document.writeln("<frameset rows=\"0, *\">"); document.writeln(&quo ...

  2. js中的字符串

    JS里并没有标准的多行字符串的表示方法,但是在用模板的时候,为了保证模板的可阅读性,我们又不可避免的使用多行字符串,所以出现了各种搞法,这里以一段jade的模板作为示例,简单总结和对比一下. 字符串相 ...

  3. hg vs git :这个世界除了svn还有别的

    最近想用版本控制软件来保存汉化文件,但又觉得SVN太麻烦,于是想到了最近较为流行的分布式版本控制工具.而Git和Mercurial(意思为水银的,于是经常缩写为Hg)自然是其中最为流行的工具.大名鼎鼎 ...

  4. RAC oracle删除数据库

    24:site2-DMS1:~ # su - oracleoracle@site2-DMS1:~> sqlplus / as sysdba SQL*Plus: Release 11.2.0.3. ...

  5. [BZOJ 3680] 吊打XXX 【模拟退火】

    题目链接:BZOJ - 3680 题目分析 这道题是SLYZ的神犇把JSOI的平衡点那道题改了一下题面变成了吊打GTY神犇..Orz 第一次写模拟退火,只能照着别人的代码写,我看的是PoPoQQQ神犇 ...

  6. mysql之索引方面的知识点总结

    索引的类型: 普通索引:这是最基本的索引类型,没唯一性之类的限制. 唯一性索引:和普通索引基本相同,但所有的索引列只能出现一次,保持唯一性. 主键:主键是一种唯一索引,但必须指定为"PRIM ...

  7. 一些记录查询的SQL语句

    -- ======================== 第三天 =========================== CREATE DATABASE php0408 CHARSET utf8 ;CR ...

  8. 【HDOJ】2830 Matrix Swapping II

    简单DP. /* 2830 */ #include <iostream> #include <string> #include <map> #include < ...

  9. MongoDB 权限管理 用户名和密码的操作

    在刚安装完毕的时候MongoDB都默认有一个admin数据库,而admin.system.users中将会保存比在其它数据库中设置的用户权限更大的用户信息.  当admin.system.users中 ...

  10. java web判断是否登录

    在使用session的情况下,如何判断是否已登录呢? 1,登录成功的后续操作 session.setAttribute(Constant2.SESSION_KEY_LOGINED_USER, user ...