RxJS - Utility Operator delayWhen

This operator delays the values emitted from the source Observable based on the timeout from another observable taken as input.


delayWhen(timeoutSelector_func: Observable): Observable


timeoutSelector_func − is an observable that decides about the timeout.

Return value

An observable will be returned that will use timeoutSelector_func output to delay the source observable.


import { fromEvent, timer } from 'rxjs';
import { delayWhen } from 'rxjs/operators';

let btn = document.getElementById("btnclick");
let btn_clicks = fromEvent(btn, 'click');
let case1 = btn_clicks.pipe(delayWhen(() => timer(1000)),);
case1.subscribe(x => console.log(x));

We have used an observable for delayWhen(), and when that observable emits the click event is emitted.


delayWhen Operator
Kickstart Your Career

Get certified by completing the course

Get Started