A presentation on Reactive Programming with RxJava that focuses on how to create observables, principles of multi threading in RxJava and error handling. This slides has a code playground available on github: https://github.com/mayowa-egbewunmi/RxJavaTraining
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
Rx java workshop
1. Reactive Programming with RxJava
Code demo available in https://github.com/mayowa-egbewunmi/RxJavaTraining
1
Presented by: Egbewunmi Mayowa
Position: Senior Software Engineer, Andela
2. 2
TABLE OF CONTENT
⬝ Introduction to Reactive Programming
⬝ Rx Observables
⬝ Multi Threading with RxJava
⬝ Error Handling
⬝ Q & A
3. Introduction
3
1. Reactive programming is a paradigm where data is emitted from a
component (a source) to another component (a subscriber). This
helps us to handle asynchronous operations effectively.
2. Asynchronous means that you can execute multiple things at a time
and you don't have to finish executing the current thing in order to
move on to next one while Synchronous basically means that you
can only execute one thing at a time.
3. Examples of asynchronous tasks: click events, HTTP requests, view
lifecycle, availability notifications, changes on a variable, change
cache events, measures from a sensor, literally anything that may
change or happen at anytime.
4. Reactive Programming is not Reactive System :)
4. Reactive Programming Paradigm
4
Observables
Observer
TransformationOperators
1. Observables emits data streams from an action
performed
2. Operators are functions for transforming and
filtering data-stream/observable e.g filter(),
map()
3. An observer subscribes to an Observable, the
observer reacts to whatever item or sequence of
items the Observable emits.
6. Threading in RxJava
1. If Thread is not specified in an Rx chain, the system main thread will be used
2. Schedulers.io is for I/O operations, Scheduler.computation is for performing intensive logic,
AndroidSchedulers.mainThread is for ui update
3. Do not perform I/O operations or intensive logic on the main thread
4. In Rx, subscribeOn operator determines on which thread “data stream” will be computed and emitted.
Without observeOn operator in Rx Chain, data will be observed from subscribeOn thread
5. In Rx, observeOn operator determines the thread for all the rx operators beneath it. To avoid bad behaviour,
observeOn operator should come immediately before subscribe()
6. Should the creator of an observable add the subscribeOn thread or the caller of the observable?
7. Error Handling In RxJava
1. Unexpected exception thrown by an Observable or its Operator
can be leaked to the Observer’s onError method but should not be swallowed but rethrown
2. Expected exception thrown by an Observable or its Operator
should not be leaked to the Observer’s onError method
3. An unexpected exception is an error whose source is unknown while an expected
exception is an error whose source is known to be from an external factor
4. RxJava Toolkits provide operators for handling exception/error
5. Sometimes we want to log an exception after the data stream has been observed/consumed,
where in the rx flow will this be done?
8. Summary
In today’s demo, we looked at how to create Rx Observables and how to apply them to
different real world scenarios. We also talked about how to perform concurrent operations
with multi threading. And finally, we discussed error handling in rxJava.
There is more!
1. Chaining, Transforming and Combining Observables
2. Rx Subjects
3. ConnectableObservable
4. Unit Testing
8