Observables are black boxes that produce data. Single Responsibility Observers consume data. Information Hiding Subscriptions are the glue. Weak Coupling
public void call(Subscriber<Cookie> subscriber) { // blocking is OK here try { while (!subscriber.isSubscribed()) { // make the cookies while we have someone to eat them subscriber.onNext(makeCookie()); } subscriber.onCompleted(); } catch (Throwable t) { subscriber.onError(t); } } });
Process decoupled from implementation, place of execution. 2. Composition of processes to form new processes. 3. Testable code. Yay for Quality! 4. Synchronization no longer a (big) issue. 5. Truly cancellable operations. (More or less.)
Mind 1. Keep data immutable. 2. Order of subscribeOn / observeOn does not matter. 3. Call subscribeOn / observeOn before subscription. 4. Use toBlockingObservable() sparingly. 5. cache() is my favorite operator. <3
are processes that emit data. • Observers use the data. • Subscriptions are what links Observables with Observers. • subscribeOn() to change execution Scheduler. • observeOn() to change observation Scheduler.