Learn RxJS
Search…
delayWhen

signature: delayWhen(selector: Function, sequence: Observable): Observable

Delay emitted values determined by provided function.

Examples

Example 1: Delay based on observable
1
// RxJS v6+
2
import { interval, timer } from 'rxjs';
3
import { delayWhen } from 'rxjs/operators';
4
5
//emit value every second
6
const message = interval(1000);
7
//emit value after five seconds
8
const delayForFiveSeconds = () => timer(5000);
9
//after 5 seconds, start emitting delayed interval values
10
const delayWhenExample = message.pipe(delayWhen(delayForFiveSeconds));
11
//log values, delayed for 5 seconds
12
//ex. output: 5s....1...2...3
13
const subscribe = delayWhenExample.subscribe(val => console.log(val));
Copied!

Additional Resources

Last modified 6mo ago