[RxJS] Transformation operators: delay and delayWhen
This lessons teaches about delay and delayWhen: simple operators that time shift.
delay(number | date)
var foo = Rx.Observable.interval(500).take(5); /*
--0--1--2--3--4|
delay(1000)
-----0--1--2--3--4|
*/ // delay(1000)
var result = foo.delay(1000); result.subscribe(
function (x) { console.log('next ' + x); },
function (err) { console.log('error ' + err); },
function () { console.log('done'); },
);
var foo = Rx.Observable.interval(500).take(5); /*
--0--1--2--3--4|
delay(date)
-----0--1--2--3--4|
*/ var date = new Date(new Date().getTime() + 1000);
var result = foo.delay(date); result.subscribe(
function (x) { console.log('next ' + x); },
function (err) { console.log('error ' + err); },
function () { console.log('done'); },
);
delayWhen( function :Observable): accept a function which return an observable:
var foo = Rx.Observable.interval(500).take(5); /*
--0--1--2--3--4|
delayWhen(x => --------0--------...)
--------0--------1--------2--------3--------4|
*/ // delay(1000)
var result = foo.delayWhen(x =>
Rx.Observable.interval(x * 1000) // For each foo, it will delay 1000 * x, so '2' --> 2000, '3' ---> 3000
); result.subscribe(
function (x) { console.log('next ' + x); },
function (err) { console.log('error ' + err); },
function () { console.log('done'); },
);
[RxJS] Transformation operators: delay and delayWhen的更多相关文章
- [RxJS] Transformation operators: debounce and debounceTime
Debounce and debounceTime operators are similar to delayWhen and delay, with the difference that the ...
- [RxJS] Creation operators: interval and timer
It is quite common to need an Observable that ticks periodically, for instance every second or every ...
- Rxjs常用operators
本文使用的是angular6内置的rxjs,版本号为6.3.3 concat 通过顺序地发出多个 Observables 的值将它们连接起来,一个接一个的. 参数: 名称 类型 属性 描述 other ...
- [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] Filtering operators: takeLast, last
Operators take(), skip(), and first() all refer to values emitted in the beginning of an Observable ...
- [RxJS] Filtering operators: take, first, skip
There are more operators in the filtering category besides filter(). This lesson will teach how take ...
- [RxJS] Creation operators: empty, never, throw
This lesson introduces operators empty(), never(), and throw(), which despite being plain and void o ...
- [RxJS] Filtering operators: distinct and distinctUntilChanged
Operator distinct() and its variants are an important type of Filtering operator. This lessons shows ...
随机推荐
- jQuery的延迟对象
之前看别人的demo,发现在延迟对象被resolve时要执行的代码,有时会写在deferred.then方法里执行,有时会写在deferred.done方法里执行. 这让对延迟对象一知半解的我非常困惑 ...
- iOS性能优化
最近采用Instruments 来分析整个应用程序的性能.发现很多有意思的点,以及性能优化和一些分析性能消耗的技巧,小结如下. Instruments使用技巧 关于Instruments官方有一个很有 ...
- cygwin使用
Cygwin是一个在windows平台上运行的类UNIX模拟环境,是cygnus solutions公司开发的自由软件(该公司开发的著名工具还有eCos,不过现已被Redhat收购). 它对于学习UN ...
- CSS样式的优先级
1.相同权值情况下,CSS样式的优先级总结来说,就是--就近原则(离被设置元素越近优先级别越高): 内联样式表(标签内部)> 嵌入样式表(当前文件中)> 外部样式表(外部文件中). 2.权 ...
- 移除Sourcesafe与VC6的绑定
整理日: 2015年2月16日 HKEY_CURRENT_USER\Software\Microsoft\DevStudio\6.0\Source Control\Disabled
- MySQL创建用户、授权等
用于MySQL5.6命令行执行成功: create database wp_people; create user wp_people@'localhost' identified by 'yrwb' ...
- OGNL-action
需要注意的是,action需要先被调用到,OGNL才能成功,因为action被执行才被压入值栈 package com.wolfgang.action; import com.opensymphony ...
- python关键字
python有多少关键字? >>> import keyword >>> keyword.kwlist ['and', 'as', 'assert', 'break ...
- 能分析压缩的日志,且基于文件输入的PYTHON代码实现
确实感觉长见识了. 希望能坚持,并有多的时间用来分析这些思路和模式. #!/usr/bin/python import sys import gzip import bz2 from optparse ...
- linux平台的office文档转pdf(程序员的菜)
需要材料: 1. Openoffice3.4(我是32位的centos,可以根据自己的系统下载指定的openoffice软件包) 下载地址:http://sourceforge.net/projec ...