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. 学渣也要搞 laravel(3)—— HTTP控制器

    1. laravel 控制器在app/Http/Controllers/ 下,你会看到里面有一个Controller.php ,之后我们创建的控制器都是继承这个总控制器的.创建控制器只需要在这里面添加 ...

  2. 2016022609 - redis哈希命令集合

    参考:http://www.yiibai.com/redis/redis_hashes.html Redis的哈希值是字符串字段和字符串值之间的映射,所以他们是表示对象的完美数据类型 在Redis中的 ...

  3. 浙工大C语言入门指南 (仅供参考)

    C语言书籍推荐 浙工大图书馆中,计算机的书都集中在三楼TP区.我个人推荐下面这么几本书. <Head First C>.Head First系列的书质量基本都很高.该书有很多插图,总体上就 ...

  4. debug(fmt,args...)调试

    1.定义宏(debug.h) #ifndef __DEBUG__H #define __DEBUG__H #include <stdio.h> #ifdef DEBUG #define d ...

  5. Data Guard配置后续检查

    Data Guard配置后续检查 1.打开生产端节点192.166.1.190上的数据库实例: SQL>startup; 2.打开容灾端节点192.166.1.60上的数据库实例: SQL> ...

  6. 【转】python3 发邮件实例(包括:文本、html、图片、附件、SSL、群邮件)

    特别留意群邮件方式,这是工作中用得多的. 附件,HTML,图片,都需要的. 文件形式的邮件 [python] view plain copy 1.#!/usr/bin/env python3 2.#c ...

  7. Hibernate 注意命名与数据库关键字的冲突 处理方法

    比如你映射了一个名称为key的属性,这是数据库所不允许的,因为它是数据库的关键字. 因此,你必须为此属性添加一对符号,即键盘上“1”键的左边的按键.

  8. Java Servlet的request使用的编码引发的思考 以及解决方法

    如果我们用浏览器填写了中文,而在服务器Servlet上没有进行编码设置,那么将会出现乱码. 出现乱码的原因是:浏览器发送的文字是以UTF-8编码发送的,然后调用request.getParameter ...

  9. [LeetCode#276] Paint Fence

    Problem: There is a fence with n posts, each post can be painted with one of the k colors. You have ...

  10. POJ 1159 Palindrome 最长公共子序列的问题

    Description A palindrome is a symmetrical string, that is, a string read identically from left to ri ...