bufferToggle(open: Observable, () => close: Observalbe : Observalbe<T[]>)

bufferToggle take two args, first is opening observable, seconde is a function which return an observable for closing.

The closeing observalbe only execute after opening emit value.

const source$ = Rx.Observable.interval(500);
const open$ = Rx.Observable.interval(1500);
const close$ = Rx.Observable.interval(1000); /** ---0---1---2---3---4---5---6---7---8---9----.... (source) -----------1-----------2-----------3--------... (open) --- ---x --- ---x --- ---x... (close)
bufferToggle(open$, () => close$) ------------------([2,3])-----([5.6])-----([8,9])--...
*/ const foo$ = source$.bufferToggle(open$, () => {
return close$;
}); foo$.subscribe(
(x) => console.debug("Next: " + x),
(err) => console.error(err),
() => console.info("DONE")
) /* "Next: 2,3"
"Next: 5,6"
"Next: 8,9"
"Next: 11,12"
...
*/

bufferWhen( () => Observable):

bufferWhen takes a function which return observable.

const source$ = Rx.Observable.interval(500);
const close$ = Rx.Observable.interval(1000); /** ---0---1---2---3---4---5---6---7---8---9----.... (source) -------0-------1-------2-------3-------4---.... (close) bufferWhen(()=>close$) -------(0)-----([1,2])-([3,4])-([5,6])--......
*/ const foo$ = source$.bufferWhen(() => close$); foo$.subscribe(
(x) => console.debug("Next: " + x),
(err) => console.error(err),
() => console.info("DONE")
) /* "Next: 0"
"Next: 1,2"
"Next: 3,4"
"Next: 5,6"
"Next: 7,8"
...
*/

[RxJS] Transformation operator: bufferToggle, bufferWhen的更多相关文章

  1. [RxJS] Transformation operator: repeat

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

  2. [RxJS] Transformation operator: buffer, bufferCount, bufferTime

    This lesson will teach you about another horizontal combination operator: buffer and its variants. B ...

  3. [RxJS] Transformation operator: scan

    All of the combination operators take two or more observables as input. These operators may also be ...

  4. [RxJS] Transformation operator: map and mapTo

    We made our first operator called multiplyBy, which looks a bit useful, but in practice we don't nee ...

  5. [RxJS] Utility operator: do

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

  6. rxjs自定义operator

    rxjs自定义operator

  7. [RxJS] Creation operator: of()

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

  8. [RxJS] Connection operator: multicast and connect

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

  9. [RxJS] Combination operator: withLatestFrom

    Operator combineLatest is not the only AND-style combinator. In this lesson we will explore withLate ...

随机推荐

  1. web系统

    现在的web系统已经越来越多的应用缓存技术,而且缓存技术确实是能实足的增强系统性能的.我在项目中也开始接触一些缓存的需求. 开始简单的就用jvm(java托管内存)来做缓存,这样对于单个应用服务器来说 ...

  2. Linux下安装gcc 、g++ 、gfortran编译器

    一.ubuntu下gcc/g++/gfortran的安装 1.安装 (1).gcc ubuntu下自带gcc编译器.可以通过“gcc -v”命令来查看是否安装. (2).g++ 安装g++编译器,可以 ...

  3. cx_Oracle使用方法二

    下载地址: https://pypi.python.org/pypi/cx_Oracle/5.2.1, 下载的时候注意数据库版本和操作系统环境. 技术手册: http://cx-oracle.read ...

  4. android 代码混淆及问题大集锦

    最近在需要对所开发的项目进行了代码混淆,在android studio中开启代码混淆其实还是挺方便的,不过因为代码混淆产生的问题非常多,特别是对于一些涉及到反射的第三方库经常因为名称的变化导致无法使用 ...

  5. (C语言)char类型与int类型相加

    #include <stdio.h> int main(void) { ; ; int c = a + b; a += b; printf("c=%d",c); //p ...

  6. C语言的编译过程和GCC编译参数

    C语言的编译一般有三个步骤: 预编译: gcc -E -o a.e a.c 预编译a.c文件,生成的目标文件名为a.e 预编译就是将include包含的头文件内容替换到C文件中,同时删除代码中没用的注 ...

  7. hadoop Yarn 编程API

    客户端编程库: 所在jar包: org.apache.hadoop.yarn.client.YarnClient 使用方法: 1 定义一个YarnClient实例: private YarnClien ...

  8. hdu 1576 A/B 拓展欧几里得算法

    A/B Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  9. 【POJ2778】AC自动机+矩阵乘法

    DNA Sequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14758 Accepted: 5716 Descrip ...

  10. 【UVALive - 5131】Chips Challenge(上下界循环费用流)

    Description A prominent microprocessor company has enlisted your help to lay out some interchangeabl ...