RxJS - Utility Operator delay



This operator delays the values emitted from the source Observable based on the timeout given.

Syntax

delay(timeout: number): Observable

Parameters

timeout − It will be in milliseconds or a Date which will delay the emission of the values from the source observable.

Return value

An observable will be returned that will use the timeout or date given to delay the source observable.

Example

import { fromEvent } from 'rxjs';
import { delay } from 'rxjs/operators';

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

Here the click event is delayed using debounce() operator

Output

delay Operator
Advertisements