Subject
Pages 33
- Home
- Additional Reading
- Alphabetical List of Observable Operators
- Async Operators
- Backpressure
- Blocking Observable Operators
- Combining Observables
- Conditional and Boolean Operators
- Connectable Observable Operators
- Creating Observables
- Error Handling
- Error Handling Operators
- Filtering Observables
- Getting Started
- How to Contribute
- How To Use RxJava
- Implementing custom operators (draft)
- Implementing Your Own Operators
- Mathematical and Aggregate Operators
- Observable
- Observable Utility Operators
- Parallel flows
- Phantom Operators
- Plugins
- Problem Solving Examples in RxJava
- Reactive Streams
- Scheduler
- String Observables
- Subject
- The RxJava Android Module
- Transforming Observables
- What's different in 2.0
- Writing operators for 2.0
- Show 18 more pages…
Clone this wiki locally
A Subject is a sort of bridge or proxy that acts both as an Subscriber and as an Observable. Because it is a Subscriber, it can subscribe to one or more Observables, and because it is an Observable, it can pass through the items it observes by reemitting them, and it can also emit new items.
For more information about the varieties of Subject and how to use them, see the ReactiveX Subject documentation.
Serializing
When you use a Subject as a Subscriber, take care not to call its onNext( ) method (or its other on methods) from multiple threads, as this could lead to non-serialized calls, which violates the Observable contract and creates an ambiguity in the resulting Subject.
To protect a Subject from this danger, you can convert it into a SerializedSubject with code like the following:
mySafeSubject = new SerializedSubject( myUnsafeSubject );A Netflix Original Production
Tech Blog | Twitter @NetflixOSS | Twitter @RxJava | Jobs