[RxJS] Filtering Operators:throttle and Throttletime

Source: Internet
Author: User

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

Throttletime (number): first emits, then cause silence
var foo = Rx.Observable.interval ($). Take (5); /* --0--1--2--3--4|  Debouncetime (+)//waits for silence, then emits  throttletime (+)//first emits, then causes silence--0-----2--- --4| */ var result = Foo.throttletime (+); 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 ($). Take (5); /* --0--1--2--3--4|  Throttle (() = Rx.Observalbe.interval (1))//first emits, then causes silence--0-----2-----4| */ var result = Foo.throttle (() = Rx.Observable.interval (+). Take (1)); Result.subscribe (   function (x) {Console.log (' next ' + x);},  function (err) {console.log (' error ' + err);},  /c13>function () {console.log (' done ');},);

Result for both:

/* "Next 0" "Next 2" "Next 4" "Done" */

[RxJS] Filtering Operators:throttle and Throttletime

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.