Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I tried to google it, but I cannot find any clear answer for that.
From the documentation, I noticed that one is operator, and one is function.
What is the difference between them? and what should I use in my code?
Thanks!
Here is the documentation link:
https://rxjs-dev.firebaseapp.com/api/operators/timeInterval
https://rxjs-dev.firebaseapp.com/api/index/function/interval
interval()
is a so called Observable creation method that returns an Observable that emits periodically an ever increasing sequence of numbers with a constant delay between them.
timeInterval()
is an operator that basically "timestamps" each emission from its source with time between the two most recent emissions.
The main and probably more obvious difference is how you use them:
range(1, 20).pipe(
timeInterval(), // `timeInterval()` is an operator
).subscribe(...); // TimeInterval objects
interval(1000).pipe( // `interval()` is a source Observable
).subscribe(...); // 0, 1, 2, ...
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.