Book Image

Learning Concurrent Programming in Scala

By : Aleksandar Prokopec
5 (1)
Book Image

Learning Concurrent Programming in Scala

5 (1)
By: Aleksandar Prokopec

Overview of this book

Table of Contents (18 chapters)
Learning Concurrent Programming in Scala
About the Author
About the Reviewers

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 +=
  "" % "rxjava-scala" % "0.19.1"