Skip to content

Latest commit

 

History

History
44 lines (32 loc) · 1.63 KB

delaywhen.md

File metadata and controls

44 lines (32 loc) · 1.63 KB

delayWhen

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

Delay emitted values determined by provided function.

Ultimate RxJS

Examples

Example 1: Delay based on observable

( StackBlitz | jsBin | jsFiddle )

// RxJS v6+
import { interval, timer } from 'rxjs';
import { delayWhen } from 'rxjs/operators';

//emit value every second
const message = interval(1000);
//emit value after five seconds
const delayForFiveSeconds = () => timer(5000);
//after 5 seconds, start emitting delayed interval values
const delayWhenExample = message.pipe(delayWhen(delayForFiveSeconds));
//log values, delayed for 5 seconds
//ex. output: 5s....1...2...3
const subscribe = delayWhenExample.subscribe(val => console.log(val));

Additional Resources


📁 Source Code: https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/delayWhen.ts