- Reference
- Observables
Observables
The MongoDB Scala Driver is an asynchronous and non blocking driver. Using the Observable
model asynchronous events become simple, composable operations, freed from the complexity of nested callbacks.
For asynchronous operations there are three interfaces Observable
, Subscription
and Observer
.
Note
The interfaces are similar to Publisher
, Subscription
and Subscriber
interfaces from the reactive streams JVM implementation. However, we prefer the name Observerable
to Publisher
and Observer
to Subscriber
for readability purposes.
Observable
The Observable
represents a MongoDB operation which emits its results to the Observer
based on demand requested by the Subscription
to the Observable
.
important
Observables can be thought of as partial functions and like partial functions nothing happens until they are called.
An Observable
can be subscribed to multiple times, with each subscription potentially causing new side effects eg: querying MongoDB or inserting data.
SingleObservable
Introduced in 2.0.0 the SingleObservable
trait is an Observable
implementation that will only return a single item.
It can be used in the same way as ordinary Observables
.
Subscription
A