Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Reactive Programming

Reactive Programming

Introduction to Reactive Programming

Avatar for sameer

sameer

July 17, 2016

Other Decks in Technology

Transcript

  1. • “Reactive programming” is a general term about programming focused

    on reacting to changes, such as data values or events. • Acting in response to a situation rather than creating or controlling it. • async** resonsive ui
  2. • When working with results set It is better to

    start processing individual result when they are ready • World has moved to push technology • Asynchronous programming is very important
  3. • JVM implementation of ReactiveX • Ported by Netflix •

    Seems like just a library but it’s also the new paradigm of programming
  4. • JVM implementation of ReactiveX • Ported by Netflix •

    Seems like just a library but it’s also the new paradigm of programming
  5. • JVM implementation of ReactiveX • Ported by Netflix •

    Seems like just a library but it’s also the new paradigm of programming
  6. Responsive A responsive system is quick to react to all

    users  — under blue skies and grey skies — in order to ensure a consistently positive user experience.
  7. Resilient A resilient system applies proper design and architecture principles

    in order to ensure responsiveness under grey skies as well as blue.
  8. Event Driven A message-driven architecture is the foundation of Reactive

    applications. A message-driven application may be event-driven, actor-based, or a combination of the two.
  9. Scalable A scalable system is easily upgraded on demand in

    order to ensure responsiveness under various load conditions.
  10. • Emits zero or more items • then it terminates

    either by successfully completing, or due to an error.
  11. Types of Observable: 1. Hot : begins emitting as soon

    as created (e.g. stream of mouse click) 2. Cold : waits until an observer subscribes it (e.g. Network request)
  12. • Observer are the consumer of the data • Observer

    listens to Observable • Subscriber is special observer that can unsubscribe from data source
  13. • The Observable represents the stream of data and can

    be subscribed to by an Observer. • Events are pushed to observer
  14. Upon subscription, the Observer can have 3 types of events

    pushed to it: 1. data via the onNext function 2. errors (Exceptions or Throwables) via the onError function 3. stream completion via the onCompleted function
  15. Perform work on specific scheduler Observable.observeOn(Scheduler s) Observe the result

    on given scheduler Observable.subscribeOn(Scheduler s) Asynchrony
  16. Creating Observable • For converting single object Observable.just() • For

    converting list or arrays of object Observable.from() • Design your own observable Observable.create()
  17. Map

  18. FlatMap List<Developer> developers = getDevelopers(); List<String> teamLanguages = Observable.from(developers). map(d

    -> d.getLanguages()). flatMap(l -> l.stream()). toList(); public class Developer { private String name; private List<String> languages; public List<String> getLanguages() { return this.languages; } }
  19. Zip

  20. Zip