RxJS Interval without delay

The following code emits intafter 5000ms, and then another in each 5000mslater:

let evens = Observable.interval(5000)
     .map(i => {
          return i * 2;
      });

 evens.subscribe((i) => {
      console.log(i);
 });

Is it possible to do this, but immediately get the first result ( 0ms), and then wait 5000mbetween subsequent results?

+6
source share
1 answer

You can use where the first parameter is the initial delay: timer()

timer(0, 5000);

Or, if you want the first element to be immediately, you can also use the operator . startWith() startWith()

January 2019: updated for RxJS 6

+12
source

Source: https://habr.com/ru/post/1671699/


All Articles