Rxjs - Operators - Delay

Signature

export declare function delay<T>(delay: number | Date, scheduler?: Scheduler): Observable<T>;

Parameters

如果给是number 那就是延迟的毫秒数

如果是日期,就是到那个时间点才会发出这个流里的值

Sample

var clicks = Rx.Observable.fromEvent(document, 'click');
var delayedClicks = clicks.delay(1000); // each click emitted after 1 second
delayedClicks.subscribe(x => console.log(x));


var clicks = Rx.Observable.fromEvent(document, 'click');
var date = new Date('May 18, 2016 15:24:00'); // in the future
var delayedClicks = clicks.delay(date); // click emitted only after that date
delayedClicks.subscribe(x => console.log(x));

这个到日期才发出值,是个牛逼的能力,就好像是你做了reminder alarm什么的
定时任务之类的