Creating Observable objects
In this section, we will study various ways of creating Observable
objects. We will learn how to subscribe to different kinds of events produced by Observable
instances and learn how to correctly create custom Observable
objects. Finally, we will discuss the difference between cold and hot observables.
An Observable
object is an object that has a method called subscribe
, which takes an object called an observer as a parameter. The observer is a user-specified object with custom event-handling logic. When we call the subscribe
method with a specific observer, we can say that the observer becomes subscribed to the respective Observable
object. Every time the Observable
object produces an event, its subscribed observers get notified.
The Rx implementation for Scala is not a part of the Scala standard library. To use Rx in Scala, we need to add the following dependency to our build.sbt
file:
libraryDependencies += "com.netflix.rxjava" % "rxjava-scala" % "0.19.1"
Now...