question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Interval: Immediately emit 0?

See original GitHub issue

Before 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:closed
  • Created 10 years ago
  • Reactions:4
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
benjchristensencommented, Jan 2, 2014

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 or startsWith(0).interval() if you don’t care about the values produced by interval.

The reason for interval and timer is that interval is a convenience overload for `timer.

The timer that would perform this is:

public static Observable<Long> timer(long initialDelay, long period, TimeUnit unit)

It would used as:

Observable.timer(0, 100, TimeUnit.MILLISECONDS)

That would immediately emit 0 and then increment 1, 2, 3, … n every 100 milliseconds.

1reaction
FireZenkcommented, Dec 29, 2016
Observable.timer(0, 100, TimeUnit.MILLISECONDS)

is deprecated but now you can use

Observable.interval(0, 100, TimeUnit.MILLISECONDS)
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found