Understanding the anatomy of an Observable
Understanding the Observable anatomy is crucial in order to learn error handling patterns. Do you remember this marble diagram, explained in Chapter 1, The Power of the Reactive Paradigm?
Let's examine the preceding diagram. If we look closer at the stream's life cycle, we can figure out that a stream has two final statuses:
- Completion status: When the stream has ended without errors and will not emit any further values. It is a SHUT DOWN.
- Error status: When the stream has ended with an error and will not emit any further values after the error is thrown. It is also a SHUT DOWN.
Only one of those two states can occur, not both, and every stream can error out once. This is the Observable contract. You may be wondering at this point, how we can recover from an error then?
This is what we will be learning in the following sections.