Java Magazine, Jan/Feb 2018
ORACLE COM JAVAMAGAZINE JANUARY FEBRUARY 2018 38 reactive programming with a single parameter which is a lambda called to receive each event The following are other forms of Subscribe depending on the events the consumer wants to receive No arguments which just triggers the processing Two arguments to process events and errors Three arguments to process events to process errors and to provide notification when the processing is complete Creating publishers and recovering from errors Of course RxJava would be quite limited if creating data streams such as Observables were limited to calling the just factory method as we did in the previous example All types of publishers support a create method to define the code to deal with new subscribers List String data Arrays asList foo bar baz Random random new Random Observable String source Observable create subscriber for String s data if random nextInt 6 0 subscriber onError new RuntimeException Bad luck for you subscriber onNext s subscriber onComplete The example above creates an Observable of String values in other words a stream of String values where the values are being picked from a predefined list We also introduced random failures The following three methods can be used to notify subscribers
You must have JavaScript enabled to view digital editions.