3. RX JAVA BY NETFLIX
• A library for composing asynchronous and
event-based programs using observable
sequences for the Java VM
• Implementation of Rx Observables from
Microsoft
• Targets the JVM not a language. Currently
supports Java, Groovy, Clojure, and Scala
• https://github.com/Netflix/RxJava
• Apache License, Version 2.0
10. CREATING OBSERVABLES
Observable<Boolean> watchTheCat =
Observable.create(observer -> {
observer.onNext(cat.isAlive());
observer.onCompleted();
return Subscriptions.empty();
});
• Executes all code when subscribed
• Not asynchronous, not really a stream
11. CREATING OBSERVABLES
Observable.create(observer -> {
Future<?> future = executorService.submit(() -> {
observer.onNext(cat.isAlive());
observer.onCompleted();
});
return Subscriptions.from(future);
});
•
•
•
•
Executes code in separate thread (from thread pool executorService)
Stream of events is delivered by the executor thread
Thread calling onNext() runs all the operations defined on observable
Future is cancelled if client unsubscribes