It is quite common to need an Observable that ticks periodically, for instance every second or every 100 miliseconds. We will learn about operators interval() and timer(), both of which are similar to setInterval() in JavaScript.

Interval(period):

You can create interval() function by you own:

var foo = Rx.Observable.create( function(Observe){
var i = ;
setInterval(function(){
Observe.next(i);
i++;
}, );
}) foo.subscribe(function (x) {
console.log('next ' + x);
}, function (err) {
console.log('error ' + err);
}, function () {
console.log('done');
});

Or:

var foo = Rx.Observable.interval();

foo.subscribe(function (x) {
console.log('next ' + x);
}, function (err) {
console.log('error ' + err);
}, function () {
console.log('done');
});

timer(delay/date, period):

var foo = Rx.Observable.timer(, ); // after 3 second delay
var date = new Date(new Date().getTime() + );
var foo = Rx.Observable.timer(date, ); // accept a date object foo.subscribe(function (x) {
console.log('next ' + x);
}, function (err) {
console.log('error ' + err);
}, function () {
console.log('done');
});

[RxJS] Creation operators: interval and timer的更多相关文章

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

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

  2. [RxJS] Creation operators: fromEventPattern, fromEvent

    Besides converting arrays and promises to Observables, we can also convert other structures to Obser ...

  3. [RxJS] Creation operators: from, fromArray, fromPromise

    The of() operator essentially converted a list of arguments to an Observable. Since arrays are often ...

  4. [RxJS] Creation operator: of()

    RxJS is a lot about the so-called "operators". We will learn most of the important operato ...

  5. [RxJS] Transformation operators: debounce and debounceTime

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

  6. [RxJS] Transformation operators: delay and delayWhen

    This lessons teaches about delay and delayWhen: simple operators that time shift. delay(number | dat ...

  7. [RxJS] Filtering operators: takeLast, last

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

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

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

  9. [RxJS] Creation operator: create()

    We have been using Observable.create() a lot in previous lessons, so let's take a closer look how do ...

随机推荐

  1. CXF处理Date类型的俩种方式

    1. CXF利用wsdl2java生成客户端时Date日期类型转换 http://cwfmaker.iteye.com/blog/1142835 2. GregorianCalendar cal = ...

  2. Objective-C学习篇05—Foundation框架简介

    iOS中所谓的框架,说到底就是一个目录,iOS提供了很多我们可以在应用程序中调用的框架.许多应用程序都使用了如Foundation.UIKit和Core Graphics这些框架.根据你为应用程序选择 ...

  3. cocos2dx 资源合并.

    文件合并之前 文件合并之后 吐槽 我们项目比较奇葩, ui用cocostudio做, 这项光荣的任务由美术接手. 这个美术是个新手, 经过我长时间的观察, 她似乎不用怎么画画. 至少在很长一段时间里, ...

  4. head First HTML与CSS读书笔记

    调整图片大小 有滚动条的图片可给不了好的用户体验,为了让图片的大小更适合浏览器窗口.这时候就需要对图片的大小进行调整看书之前.我调整图片大小的方式是在<img>元素使用 width 和 h ...

  5. (转)ligerUI 使用教程之Tip介绍与使用

    概述:   ligertip是ligerUI系列插件中的tooltip类插件,作用是弹一个浮动层,起提示作用   阅读本文要求具备jQuery的基本知识,不然文中的javascript代码不易理解 截 ...

  6. frame与iframe的区别?

    1.frame不能脱离frameSet单独使用,iframe可以 2.frame不能放在body中,否则不能正常显示 3.嵌套在frameSet中的iframe必需放在body中,不嵌套在frameS ...

  7. Kohana框架ORM类的基本使用

    1.首先需要创建一个模型类,以user为例,在application/classes/model/user.php路径下创建user.php,并且一个表对应一个模型,且表名必须在类名后加“S”,即表名 ...

  8. Retrofit2.0+OkHttp设置统一的请求头(request headers)

    有时候要求Retrofit2的接口中每个都要增加上headers,又不想做重复的事情,可以使用这种方法来为每个request请求都设置上相同的请求头header. 修改请求头request heade ...

  9. JDBC与javaBean

    1.JDBC的概念: Java数据库连接技术(Java DataBase Connectivity)能实现java程序对各种数据库的访问, 由一组使用java语言编写的类 和 接口(jdbc api) ...

  10. 通过ctypes获得python windows process的内存使用情况

    通过ctypes 类库中的win32方法GetProcessMemoryInfo()获得当前进程的内存使用情况.该函数可以在32或者64位,python2.6+及python3.x之上都能有用. &q ...