function
stable
Delays the emission of items from the source Observable by a given timeout or until a given Date.
delay<T>(delay: number | Date, scheduler: SchedulerLike = async): MonoTypeOperatorFunction<T>
delay | The delay duration in milliseconds (a |
scheduler | Optional. Default is The |
MonoTypeOperatorFunction<T>
: An Observable that delays the emissions of the source Observable by the specified timeout or Date.
Time shifts each item by some specified amount of milliseconds.
If the delay argument is a Number, this operator time shifts the source Observable by that amount of time expressed in milliseconds. The relative time intervals between the values are preserved.
If the delay argument is a Date, this operator time shifts the start of the Observable execution until the given date occurs.
Delay each click by one second
import { fromEvent } from 'rxjs'; import { delay } from 'rxjs/operators'; const clicks = fromEvent(document, 'click'); const delayedClicks = clicks.pipe(delay(1000)); // each click emitted after 1 second delayedClicks.subscribe(x => console.log(x));
Delay all clicks until a future date happens
import { fromEvent } from 'rxjs'; import { delay } from 'rxjs/operators'; const clicks = fromEvent(document, 'click'); const date = new Date('March 15, 2050 12:00:00'); // in the future const delayedClicks = clicks.pipe(delay(date)); // click emitted only after that date delayedClicks.subscribe(x => console.log(x));
© 2015–2018 Google, Inc., Netflix, Inc., Microsoft Corp. and contributors.
Code licensed under an Apache-2.0 License. Documentation licensed under CC BY 4.0.
https://rxjs.dev/api/operators/delay