[RxJS] Creation operators: interval and timer
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的更多相关文章
- [RxJS] Creation operators: empty, never, throw
This lesson introduces operators empty(), never(), and throw(), which despite being plain and void o ...
- [RxJS] Creation operators: fromEventPattern, fromEvent
Besides converting arrays and promises to Observables, we can also convert other structures to Obser ...
- [RxJS] Creation operators: from, fromArray, fromPromise
The of() operator essentially converted a list of arguments to an Observable. Since arrays are often ...
- [RxJS] Creation operator: of()
RxJS is a lot about the so-called "operators". We will learn most of the important operato ...
- [RxJS] Transformation operators: debounce and debounceTime
Debounce and debounceTime operators are similar to delayWhen and delay, with the difference that the ...
- [RxJS] Transformation operators: delay and delayWhen
This lessons teaches about delay and delayWhen: simple operators that time shift. delay(number | dat ...
- [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 operator: create()
We have been using Observable.create() a lot in previous lessons, so let's take a closer look how do ...
随机推荐
- singleTask TaskAffinity allowTaskReparenting
关于singleTask TaskAffinity allowTaskReparenting 一.Activity的LaunchMode 1.standard 2.singleTop:FLAG_ACT ...
- Swift - 27 - 使用元组让函数返回多个值
//: Playground - noun: a place where people can play import UIKit // 定义一个数组 var userScores:[Int]? = ...
- JavaScript的“闭包”到底是什么
在JavaScripot函数闭包的定义中,一般都有一个outer 函数,一个inner函数.那么“闭包”到底是指outer函数呢,还是指inner函数? 从官方定义来看,并不清楚:A closure ...
- jQuery firefox chrome IE 绑定mousewheel事件
$doc.on('mousewheel DOMMouseScroll',function(){ $htmlBody.stop(true); $goTop.stop(true); });
- Java简介(3)-基本语法
1.大小写敏感 2.类名 3.方法名. 4.源文件名
- js循环便利json数据
var data=[{name:"a",age:12},{name:"b",age:11},{name:"c",age:13},{name: ...
- 在sublimetext上打造一个兼容virtualenv的web&python开发环境
利用Sublimetext3&virtualenv 打造一个Web&Python IDE 注: 环境:window|python3;以下使用的sublimetext插件均用packag ...
- 10:Hello, World!的大小
总时间限制: 1000ms 内存限制: 65536kB 描述 还记得在上一章里,我们曾经输出过的“Hello, World!”吗? 它虽然不是本章所涉及的基本数据类型的数据,但我们同样可以用siz ...
- [异常解决] Make nRF51 DFU Project Appear "fatal error: uECC.h: No such file or directory"
What's the problem When I make the nRF51's DFU project appear "no uECC.h" error: And then ...
- FPGA同步复位异步复位
今天看了篇博客, 是拿altera的芯片和软件作例子的,讲同步异步复位的: http://blog.sina.com.cn/s/blog_bff0927b0101aaii.html 还有一个博客, h ...