Member-only story

RxJS — delay vs delayWhen operator

Vinodh Thangavel
2 min readDec 9, 2021

--

delay operator

The delay operator is used to delay the emission with predefined period of time.

We can delay the emission by two types of values.

  • Time to delay in milliseconds
  • Delay until a given date
const source$ = of(2,1,4).pipe(delay(3000));source$.subscribe(console.log); //prints 2 1 4 but after 3 seconds

It will wait for 3 seconds and print then emission starts. Please note that it will not wait for 3 seconds for each value emission

first value is emitted just before the second value

You can see from the above marble diagrams that values are passing through delay operator is delayed.

Please note the difference between the diagrams, distance between first and second emitted values. We can see clearly that in both diagrams, emission of second and third values unchanged.

In order words, delay operator will delay the stream to start to emitting, it will not apply delay on every emission.

Delay by date

--

--

Vinodh Thangavel
Vinodh Thangavel

Written by Vinodh Thangavel

Passionate lifelong learner, coding enthusiast, and dedicated mentor. My journey in tech is driven by curiosity, creativity, and a love for sharing knowledge.

No responses yet