zoukankan      html  css  js  c++  java
  • [RxJS] Transformation operator: buffer, bufferCount, bufferTime

    This lesson will teach you about 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 to specify when to close the buffers.

    buffer(close observable): According to another observalbe to group items.

    var foo = Rx.Observable.of('h', 'e', 'l', 'l', 'o')
      .zip(Rx.Observable.interval(600).take(5), (x,y) => x);
    var bar = Rx.Observable.interval(900).take(3);
    
    /*
    -----h-----e-----l-----l-----o|       (foo)
    --------0--------1--------2|          (bar)
    
            buffer(bar)
    
    --------h--------e--------ll|
    */
    
    var result = 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): 

    var foo = Rx.Observable.of('h', 'e', 'l', 'l', 'o')
      .zip(Rx.Observable.interval(600).take(5), (x,y) => x);
    
    /*
    -----h-----e-----l-----l-----o|       (foo)
    --------x--------x--------x|          (900ms)
    
            bufferTime(900)
    
    --------h--------e--------ll|
    */
    
    var result = 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):

    var foo = Rx.Observable.of('h', 'e', 'l', 'l', 'o')
      .zip(Rx.Observable.interval(600).take(5), (x,y) => x);
    
    /*
    -----h-----e-----l-----l-----o|       (foo)
    
            bufferCount(2)
    
    ----------([h,e])------([l,l])([o|])l
    */
    
    var result = 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"
      
      */
  • 相关阅读:
    关于跨域,以及跨域的几种方式
    跨域资源共享 CORS 详解
    python 协程与go协程的区别
    查看Mysql正在执行的事务、锁、等待
    undo log,当前读和快照读,redo log----与mvcc
    如何查找MySQL中查询慢的SQL语句
    dbForge Studio 2020 for MySQL v9.0.338破解软件包下载
    阿里云数据盘挂载完整过程
    [原][python]递归遍历文件夹下所有小文件,并删除
    [转][数据结构]R树 RTree
  • 原文地址:https://www.cnblogs.com/Answer1215/p/5535668.html
Copyright © 2011-2022 走看看