[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" */
[RxJS] Transformation operator: buffer, bufferCount, bufferTime的更多相关文章
- [RxJS] Transformation operator: repeat
Operator repeat() is somewhat similar to retry(), but is not for handling operators. In this lesson ...
- [RxJS] Transformation operator: scan
All of the combination operators take two or more observables as input. These operators may also be ...
- [RxJS] Transformation operator: map and mapTo
We made our first operator called multiplyBy, which looks a bit useful, but in practice we don't nee ...
- [RxJS] Transformation operator: bufferToggle, bufferWhen
bufferToggle(open: Observable, () => close: Observalbe : Observalbe<T[]>) bufferToggle take ...
- [RxJS] Utility operator: do
We just saw map which is a transformation operator. There are a couple of categories of operators, s ...
- rxjs自定义operator
rxjs自定义operator
- [RxJS] Creation operator: of()
RxJS is a lot about the so-called "operators". We will learn most of the important operato ...
- [RxJS] Connection operator: multicast and connect
We have seen how Subjects are useful for sharing an execution of an RxJS observable to multiple obse ...
- [RxJS] Combination operator: withLatestFrom
Operator combineLatest is not the only AND-style combinator. In this lesson we will explore withLate ...
随机推荐
- 博客系统-3.0CodeIgniter系统SAE版本的配置 application/config/
autoload.php(系统启动时自动加载的文件:包,类库,驱动,方法助手,配置) $autoload['libraries'] = array('database', 'access', 'pag ...
- php Imagick库readImage()报Postscript delegate failed 解决方法(失效)
需要安装 ghostscript http://www.ghostscript.com/download/gsdnld.html
- ExecuteNonQuery&& ExecuteQuery 区别
前些日子作一些数据项目的时候 在ADO.NET 中处理 ExecuteNonQuery()方法时,总是通过判断其返回值是否大于0来判断操作时候成功 .但是实际上并不是这样的,好在处理的数据操作多时 修 ...
- 从用python自动生成.h的头文件集合和类声明集合到用python读写文件
最近在用python自动生成c++的类.因为这些类会根据需求不同产生不同的类,所以需要用python自动生成.由于会产生大量的类,而且这些类是变化的.所以如果是在某个.h中要用include来加载这些 ...
- dubbo 负载均衡中策略决策
在dubbo中的服务端负载均衡配置,如果像以下情况,将需要决策最终的负载策略问题: <dubbo:application name="hello-world-server" ...
- 从MVC到前后端分离
摘要:MVC模式早在上个世纪70年代就诞生了,直到今天它依然存在,可见生命力相当之强.MVC模式最早用于Smalltalk语言中,最后在其它许多开发语言中都得到了很好的应用,例如,Java中的Stru ...
- FutureTask源码解读
import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.ut ...
- Linux网络编程-----Socket地址API
(1) 通用socket地址 socket网络编程接口中表示socket地址的是结构体sockaddr,其定义如下: #include<bits/socket.h> struct sock ...
- MacOS 下端口占用解决办法
现象:Mac下,IDEA正常关闭tomcat时,仍旧抛出8009 端口被占用. 解决: 1. 终端(命令行)上,输入命令 lsof -i tcp: 2. 找到这个进程的 PID,好吧,kill掉它 k ...
- inline-block的垂直居中
inline-block和inline都是不需要浮动就可以成行的,但是他们成行的效果不同. inline和浮动中的block是顶着上边,inline-block是像被一根绳子从垂直方向的中心穿过去. ...