delay

签名: delay(delay: number | Date, scheduler: Scheduler): Observable

根据给定时间延迟发出值。

delay - 图1

示例

示例 1: 延迟时间持续增加

( jsBin |
jsFiddle )

  1. import { of } 'rxjs/observable/of';
  2. import { merge } from 'rxjs/observable/merge';
  3. import { mapTo, delay } from 'rxjs/operators';
  4. // 发出一项
  5. const example = of(null);
  6. // 每延迟一次输出便增加1秒延迟时间
  7. const message = merge(
  8. example.pipe(mapTo('Hello')),
  9. example.pipe(mapTo('World!'), delay(1000)),
  10. example.pipe(mapTo('Goodbye'), delay(2000)),
  11. example.pipe(mapTo('World!'), delay(3000))
  12. );
  13. // 输出: 'Hello'...'World!'...'Goodbye'...'World!'
  14. const subscribe = message.subscribe(val => console.log(val));

相关食谱

其他资源


:file_folder: 源码: https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/delay.ts