[RxJS] Transformation Operator:buffer, BufferCount, BufferTime

Source: Internet
Author: User

This lesson would teach you on another horizontal combination operator:buffer and its variants. Buffer groups consecutive values together, emitting the output as an array. The buffer variants and their arguments allow-specify when to close the buffers.

Buffer (Close observable): According to another observalbe to group items.

varFoo = Rx.Observable.of (' h ', ' e ', ' l ', ' l ', ' O '). zip (Rx.Observable.interval (Take (5), (x, y) =x);varBar = Rx.Observable.interval (in). Take (3);/*-----H-----E-----L-----L-----o|          (foo)--------0--------1--------2| (bar) buffer (bar)--------H--------e--------ll|*/varresult =Foo.buffer (bar); Result.subscribe (function(x) {Console.log (' next ' +x); },  function(ERR) {console.log (' error ' +err); },  function() {console.log (' done '));    },); /*"Next H" "Next E" "next L,l" "Done"*/

BufferTime (number):

varFoo = Rx.Observable.of (' h ', ' e ', ' l ', ' l ', ' O '). zip (Rx.Observable.interval (Take (5), (x, y) =x);/*-----H-----E-----L-----L-----o|          (foo)--------x--------x--------x| (900ms) bufferTime--------h--------e--------ll|*/varresult = Foo.buffertime (900); Result.subscribe (function(x) {Console.log (' next ' +x); },  function(ERR) {console.log (' error ' +err); },  function() {console.log (' done '));    },); /*"Next H" "Next E" "next L,l" "Done"*/

BufferCount (number):

varFoo = Rx.Observable.of (' h ', ' e ', ' l ', ' l ', ' O '). zip (Rx.Observable.interval (Take (5), (x, y) =x);/*-----H-----E-----L-----L-----o| (foo) bufferCount (2)----------([h,e])------([l,l]) ([o|]) L*/varresult = Foo.buffercount (2); Result.subscribe (function(x) {Console.log (' next ' +x); },  function(ERR) {console.log (' error ' +err); },  function() {console.log (' done '));    },); /*"Next H,e" "Next l,l" "Next O" "Done"*/

[RxJS] Transformation Operator:buffer, BufferCount, BufferTime

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.