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的更多相关文章

  1. [RxJS] Transformation operators: debounce and debounceTime

    Debounce and debounceTime operators are similar to delayWhen and delay, with the difference that the ...

  2. [RxJS] Creation operators: interval and timer

    It is quite common to need an Observable that ticks periodically, for instance every second or every ...

  3. Rxjs常用operators

    本文使用的是angular6内置的rxjs,版本号为6.3.3 concat 通过顺序地发出多个 Observables 的值将它们连接起来,一个接一个的. 参数: 名称 类型 属性 描述 other ...

  4. [RxJS] Transformation operator: repeat

    Operator repeat() is somewhat similar to retry(), but is not for handling operators. In this lesson ...

  5. [RxJS] Transformation operator: scan

    All of the combination operators take two or more observables as input. These operators may also be ...

  6. [RxJS] Filtering operators: takeLast, last

    Operators take(), skip(), and first() all refer to values emitted in the beginning of an Observable ...

  7. [RxJS] Filtering operators: take, first, skip

    There are more operators in the filtering category besides filter(). This lesson will teach how take ...

  8. [RxJS] Creation operators: empty, never, throw

    This lesson introduces operators empty(), never(), and throw(), which despite being plain and void o ...

  9. [RxJS] Filtering operators: distinct and distinctUntilChanged

    Operator distinct() and its variants are an important type of Filtering operator. This lessons shows ...

随机推荐

  1. 设置(TableViewController)通用框架

    本文学习于传播播客.李明杰老师.感谢

  2. ubuntu下openGL的配置方法

    This is a simple tutorial to show a new linux user (such as myself) how to setup freeglut and OpenGl ...

  3. Entity Framework 实践系列 —— 搞好关系 - 两情相悦(双向一对一)【转载】

    Entity Framework 实践系列 —— 搞好关系 - 两情相悦(双向一对一) 自从搞好了单向一对一关系,装满代码的心中塞进了挥之不去的情丝 —— 单相思.谁都知道音乐世界离不开情感,可谁又知 ...

  4. Junit4拓展工具JCategory与Testng的Group功能比较

    前言 笔者前段时间分享过一遍文章,关于如何通过引入新注解来扩展Junit4,以解决Process上的问题: JUnit扩展:引入新注解Annotation 最近在跟外面的同事聊的时候,得知Testng ...

  5. 运行从别处复制过来的linux可执行程序

    1, 首先ldd看看缺不缺so文件,如果不缺可忽略下面的文字,直接执行 2, 先看看缺的这些库在系统上有没有,这些库可通过安装开发包,第三方软件进行安装 3, 找到可能会包含这些库的可执行程序,ldd ...

  6. C++中Reference与指针(Pointer)的使用对比

    整理日: 2015年3月18日 引用(reference)和指针(pointer)是学C++过程中最令人头疼的问题,常常不知道什么时候用哪个合适,又常常弄混.找到Dan Saks的这篇文章,讲的很清楚 ...

  7. bzoj 1067: [SCOI2007]降雨量 模擬

    1067: [SCOI2007]降雨量 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 2010  Solved: 503[Submit][Status] ...

  8. [BZOJ 1336] [Balkan2002] Alien最小圆覆盖 【随机增量法】

    题目链接:BZOJ - 1336 题目分析 最小圆覆盖有一个算法叫做随机增量法,看起来复杂度像是 O(n^3) ,但是可以证明其实平均是 O(n) 的,至于为什么我不知道= = 为什么是随机呢?因为算 ...

  9. 单片机Keil软件仿真与调试技巧

    一.引言 单片机软件开发过程中,软件调试遇到的各种问题常令初学者感到不知所措.实际上.各种仿真开发软件的程序调试基本方法和技巧大同小异,掌握正确的程序调试基本技巧.对于排查这些程序错误问题可以起到举一 ...

  10. 【转】android 完全退出应用程序

    原文网址:http://www.yoyong.com/archives/199 android退出应用程序会调用android.os.Process.killProcess(android.os.Pr ...