Interval: Immediately emit 0?
See original GitHub issueBefore it’s too late, I’d like to discuss the following question: When should Observable.interval(t)
emit its first element (which is 0):
a) right after the observer subscribed, or
b) only after a delay of t
?
Currently, we have b), but I’d vote for a), because I’ve seen many people stumble over this. I think it makes more sense if after n*t
time, it emits n
.
Or a third possiblilty:
c) start with 1, and emit it after a delay of t
Issue Analytics
- State:
- Created 10 years ago
- Reactions:4
- Comments:7 (4 by maintainers)
Top Results From Across the Web
rxjs - How do I make an Observable Interval start immediately ...
Note: With this solution, 0 value will be emitted twice (one time immediately by startWith , and one time by interval stream after...
Read more >interval - RxJS
interval returns an Observable that emits an infinite sequence of ascending integers, with a constant interval of time of your choosing between those...
Read more >interval - Learn RxJS
Emit numbers in sequence based on provided timeframe. ... Example 1: Emit sequence of values at 1 second interval ... //output: 0,1,2,3,4,5.
Read more >setInterval() - Web APIs - MDN Web Docs
This method returns an interval ID which uniquely identifies the interval, ... The returned intervalID is a numeric, non-zero value which ...
Read more >Fixed Time Interval - an overview | ScienceDirect Topics
First, a fixed time interval tdead after each successful detection during ... Then, the probability that n photons will be emitted in a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Sitting here with @headinthebox to get this answered …
The
interval
operator will always have a delay before emitting, so it behaves correctly.If an immediate values is wanted then use
timer
orstartsWith(0).interval()
if you don’t care about the values produced by interval.The reason for
interval
andtimer
is thatinterval
is a convenience overload for `timer.The
timer
that would perform this is:It would used as:
That would immediately emit 0 and then increment 1, 2, 3, … n every 100 milliseconds.
is deprecated but now you can use