Member-only story
RxJS — delay vs delayWhen operator
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
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