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

var foo = Rx.Observable.interval(500).take(5);

/*
--0--1--2--3--4|
debounceTime(1000) // waits for silence, then emits
throttleTime(1000) // first emits, then causes silence
--0-----2-----4|
*/ var result = foo.throttleTime(1000); result.subscribe(
function (x) { console.log('next ' + x); },
function (err) { console.log('error ' + err); },
function () { console.log('done'); },
);

throttle( () => Observable):

var foo = Rx.Observable.interval(500).take(5);

/*
--0--1--2--3--4|
throttle( () => Rx.Observalbe.interval(1000).take(1)) // first emits, then causes silence
--0-----2-----4|
*/ var result = foo.throttle( () => Rx.Observable.interval(1000).take(1)); result.subscribe(
function (x) { console.log('next ' + x); },
function (err) { console.log('error ' + err); },
function () { console.log('done'); },
);

Result for both:

/*

"next 0"
"next 2"
"next 4"
"done" */

[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. C# Winform 开发框架

    C/S系统开发框架-企业版 V4.0 (Enterprise Edition) 简介: http://www.csframework.com/cs-framework-4.0.htm 视频下载: 百度 ...

  2. centos下的lnmp环境搭建

    1.配置centos的第三方yum源,因为原始的yum是无法安装nginx的 wget http://www.atomicorp.com/installers/atomic  下载atomic yum ...

  3. POJ 3083 Children of the Candy Corn bfs和dfs

      Children of the Candy Corn Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8102   Acc ...

  4. Android开源项目发现--- 工具类快速开发篇(持续更新)

    1. Guava Google的基于java1.6的类库集合的扩展项目 包括collections, caching, primitives support, concurrency librarie ...

  5. Git 、CVS、SVN比较

    Git .CVS.SVN比较 项目源代码的版本管理工具中,比较常用的主要有:CVS.SVN.Git 和 Mercurial  (其中,关于SVN,请参见我先前的博客:SVN常用命令 和 SVN服务器配 ...

  6. centos6.5 设置静态ip地址

    vim /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 #描述网卡对应的设备别名,例如ifcfg-eth0的文件中它为eth0BOOTPRO ...

  7. Sublime Text 2 中文包

    下载中文包 大家直接下载吧 http://download.csdn.net/detail/onebelowzero2012/9331981 注意解压路径,一开始我以为D:\MySublime\Sub ...

  8. winphone 开发学习笔记(2)

    导航 NavigationService.Navigate(new Uri("xxxx.xaml",UriKind.Relative)) xxx表示要跳转的目标页面 页面和页面导航 ...

  9. Linux学习笔记10——文件I/O之一

    UNIX系统中的大多数文件I/O只需要用到5个函数:open,read,write,lseek以及close 文件描述符 文件描述符是一个非负整数,所有打开的文件都通过文件描述符引用 文件描述符的变化 ...

  10. PHP_SELF、 SCRIPT_NAME、 REQUEST_URI 区别

    $_SERVER[PHP_SELF], $_SERVER[SCRIPT_NAME], $_SERVER['REQUEST_URI'] 在用法上是非常相似的,他们返回的都是与当前正在使用的页面地址有关的 ...