delayWhen
优质
小牛编辑
134浏览
2023-12-01
delayWhen
函数签名: delayWhen(selector: Function, sequence: Observable): Observable
延迟发出值,延迟时间由提供函数决定。
示例
示例 1: 基于 observable 的延迟
( StackBlitz | jsBin | jsFiddle )
// RxJS v6+
import { interval, timer } from 'rxjs';
import { delayWhen } from 'rxjs/operators';
// 每1秒发出值
const message = interval(1000);
// 5秒后发出值
const delayForFiveSeconds = () => timer(5000);
// 5秒后,开始发出 interval 延迟的值
const delayWhenExample = message.pipe(delayWhen(delayForFiveSeconds));
// 延迟5秒后输出值
// 例如, 输出: 5s....1...2...3
const subscribe = delayWhenExample.subscribe(val => console.log(val));
其他资源
- delayWhen :newspaper: - 官方文档
- 转换操作符: delay 和 delayWhen :video_camera: :dollar: - André Staltz
源码: https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/delayWhen.ts