Skip to Main Content
Advanced Python Programming
book

Advanced Python Programming

by Dr. Gabriele Lanaro, Quan Nguyen, Sakis Kasampalis
February 2019
Intermediate to advanced content levelIntermediate to advanced
672 pages
16h 50m
English
Packt Publishing
Content preview from Advanced Python Programming

Hot and cold observables

In the preceding section, we learned how to create an observable using the Observable.from_iterable method. RxPy provides many other tools to create more interesting event sources.

Observable.interval takes a time interval in milliseconds, period, and will create an observable that emits a value every time the period has passed. The following line of code can be used to define an observable, obs, that will emit a number, starting from zero, every second. We use the take operator to limit the timer to four events:

    obs = Observable.interval(1000)    obs.take(4).subscribe(print)    # Output:    # 0    # 1    # 2    # 3

A very important fact about Observable.interval is that the timer doesn't start until we subscribe. We can observe this ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Advanced Python Programming - Second Edition

Advanced Python Programming - Second Edition

Quan Nguyen
Expert Python Programming - Third Edition

Expert Python Programming - Third Edition

Michał Jaworski, Tarek Ziadé, Cody Jackson
Python Workout

Python Workout

Reuven M. Lerner

Publisher Resources

ISBN: 9781838551216Supplemental Content