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));

其他资源


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

results matching ""

    No results matching ""