Debounce is known to be a rate-limiting operator, but it's not the only one. This lessons introduces you to throttleTime and throttle, which only drop events (without delaying them) to accomplish rate limiting.

 throttleTime(number): first emits, then cause silence

  1. var foo = Rx.Observable.interval(500).take(5);
  2.  
  3. /*
  4. --0--1--2--3--4|
  5. debounceTime(1000) // waits for silence, then emits
  6. throttleTime(1000) // first emits, then causes silence
  7. --0-----2-----4|
  8. */
  9.  
  10. var result = foo.throttleTime(1000);
  11.  
  12. result.subscribe(
  13. function (x) { console.log('next ' + x); },
  14. function (err) { console.log('error ' + err); },
  15. function () { console.log('done'); },
  16. );

throttle( () => Observable):

  1. var foo = Rx.Observable.interval(500).take(5);
  2.  
  3. /*
  4. --0--1--2--3--4|
  5. throttle( () => Rx.Observalbe.interval(1000).take(1)) // first emits, then causes silence
  6. --0-----2-----4|
  7. */
  8.  
  9. var result = foo.throttle( () => Rx.Observable.interval(1000).take(1));
  10.  
  11. result.subscribe(
  12. function (x) { console.log('next ' + x); },
  13. function (err) { console.log('error ' + err); },
  14. function () { console.log('done'); },
  15. );

Result for both:

  1. /*
  2.  
  3. "next 0"
  4. "next 2"
  5. "next 4"
  6. "done"
  7.  
  8. */

[RxJS] Filtering operators: throttle and throttleTime的更多相关文章

  1. [RxJS] Filtering operators: take, first, skip

    There are more operators in the filtering category besides filter(). This lesson will teach how take ...

  2. [RxJS] Filtering operators: distinct and distinctUntilChanged

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

  3. [RxJS] Filtering operators: takeLast, last

    Operators take(), skip(), and first() all refer to values emitted in the beginning of an Observable ...

  4. [RxJS] Filtering operators: skipWhile and skipUntil

    After takeUntil() and takeWhile() function, let's have a look on skipWhile() and skilUntil() functio ...

  5. [RxJS] Filtering operators: takeUntil, takeWhile

    take(), takeLast(), first(), last(), those opreators all take number or no param. takeUtil and takeW ...

  6. [RxJS] Transformation operators: debounce and debounceTime

    Debounce and debounceTime operators are similar to delayWhen and delay, with the difference that the ...

  7. [RxJS] Transformation operators: delay and delayWhen

    This lessons teaches about delay and delayWhen: simple operators that time shift. delay(number | dat ...

  8. [RxJS] Creation operators: interval and timer

    It is quite common to need an Observable that ticks periodically, for instance every second or every ...

  9. [RxJS] Creation operators: empty, never, throw

    This lesson introduces operators empty(), never(), and throw(), which despite being plain and void o ...

随机推荐

  1. AS3.0定义变量的访问范围

    在AS3.0中变量的默认访问范围是:internal:包内成员可以访问,包外不可访问.AS2.0默认访问范围是public

  2. smarty模板引擎原理解析

    //php 控制器文件 <?php//引入模板引擎文件include("20130304.php");$smarty =newTinySmarty();$qq_numbers ...

  3. Android 安全概述

    1. 保密: 信息.文档加密.解密 2. 鉴别.认证:就像确认与我们打电话的确实是XXX,而不是骗子 3. 完整性:信息不能被篡改, 4. 不可否认性:确定信息有who产生,并且将来不能否认

  4. Android 下拉刷新控件Android-PullToRefresh

    需要用到一个开源库 Android-PullToRefresh https://github.com/chrisbanes/Android-PullToRefresh ---------------- ...

  5. WPF后台访问XAML元素

    当我们需要从后台访问xaml文件时,我们可以通过这样的方式来操作: private void button1_Click(object sender, RoutedEventArgs e) { Sys ...

  6. Windows7のping応答の設定

    2015年11月13日 18時09分 wanglinqiang整理 ping応答しない場合.ping応答させる.させない等の設定 1.スタート(左下のウィンドウズのロゴ)⇒コントロールパネルを選択. ...

  7. 区分html与css中的属性

    CSS中id与Class的区别 1.在CSS文件里书写时,ID加前缀"#":CLASS用"." 2.id一个页面只可以使用一次:class可以多次引用. 3.I ...

  8. matlab的cell数组

    matlab的cell数组 元胞数组: 元胞数组是MATLAB的一种特殊数据类型,可以将元胞数组看做一种无所不包的通用矩阵,或者叫做广义矩阵.组成元胞数组的元素可以是任何一种数据类型的常数或者常量,每 ...

  9. wcf纯代码创建控制台应用

    https://svn.apache.org/repos/asf/incubator/stonehenge/contrib/stocktrader/dotnet/ stocktrader项目的dotn ...

  10. 移动存储卡仍然用FAT32文件系统的真相

    微软在2001年就为自家的XP系统的本地磁盘默认使用了NTFS文件系统,但是12年之后,市面上的USB可移动设备和SD卡等外置存储器仍然在用着FAT32文件格式,这是什么理由让硬件厂商选择过时的文件系 ...