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

Looking Ahead To RxJava 2 (Droidcon NYC 2016)

Looking Ahead To RxJava 2 (Droidcon NYC 2016)

Development on the next major version of RxJava is underway. While the operators remain largely unchanged, Observable creation, subscription management, and backpressure has been completely overhauled in this new version. This talk will be an exploration on not only what has changed but also the reasons behind why these changes were made. We'll also talk about how both libraries and applications can migrate to supporting RxJava 2 as well as interop between the two versions. No prior knowledge of RxJava is strictly required, although concepts, terms, and comparisons will be made that do assume some prior knowledge.

Video: soon

54879f243e5b72eedb2d379bed6fda27?s=128

Jake Wharton
PRO

September 29, 2016
Tweet

Transcript

  1. Looking Ahead To 
 RxJava 2 Jake Wharton

  2. Reactive Streams ...is an initiative to provide a standard for

    asynchronous stream processing with non-blocking back pressure.
  3. Reactive Streams interface Publisher<T> {
 void subscribe(Subscriber<? super T> s);


    }A
  4. Reactive Streams interface Publisher<T> {
 void subscribe(Subscriber<? super T> s);


    }A interface Subscriber<T> {
 void onNext(T t);
 void onComplete();
 void onError(Throwable t);
 }B
  5. Reactive Streams interface Publisher<T> {
 void subscribe(Subscriber<? super T> s);


    }A interface Subscriber<T> {
 void onNext(T t);
 void onComplete();
 void onError(Throwable t);
 void onSubscribe(Subscription s);
 }B
  6. Reactive Streams interface Publisher<T> {
 void subscribe(Subscriber<? super T> s);


    }A interface Subscriber<T> {
 void onNext(T t);
 void onComplete();
 void onError(Throwable t);
 void onSubscribe(Subscription s);
 }B interface Subscription {
 void request(long n);
 void cancel();
 }C
  7. Reactive Streams interface Publisher<T> {
 void subscribe(Subscriber<? super T> s);


    }A interface Subscriber<T> {
 void onNext(T t);
 void onComplete();
 void onError(Throwable t);
 void onSubscribe(Subscription s);
 }B interface Subscription {
 void request(long n);
 void cancel();
 }C interface Processor<T, R> extends Subscriber<T>, Publisher<R> {
 }D

  8. Reactive Streams class RxReactiveStreams {
 static <T> Publisher<T> toPublisher(Observable<T> o)

    { … }
 static <T> Observable<T> toObservable(Publisher<T> p) { … }
 static <T> Publisher<T> toPublisher(Single<T> o) { … }
 static <T> Single<T> toSingle(Publisher<T> p) { … }
 static <T> Publisher<T> toPublisher(Completable o) { … }
 static Completable toCompletable(Publisher<?> p) { … }
 }
  9. Reactive Streams class RxReactiveStreams {
 static <T> Publisher<T> toPublisher(Observable<T> o)

    { … }
 static <T> Observable<T> toObservable(Publisher<T> p) { … }
 static <T> Publisher<T> toPublisher(Single<T> o) { … }
 static <T> Single<T> toSingle(Publisher<T> p) { … }
 static <T> Publisher<T> toPublisher(Completable o) { … }
 static Completable toCompletable(Publisher<?> p) { … }
 } github.com/ReactiveX/RxJavaReactiveStreams
  10. Reactive Streams interface Subscriber<T> {
 void onNext(T t);
 void onComplete();


    void onError(Throwable t);
 void onSubscribe(Subscription s);
 }B
  11. Reactive Streams interface Subscriber<T> {
 void onNext(T t);
 void onComplete();


    void onError(Throwable t);
 void onSubscribe(Subscription s);
 }B Calling onSubscribe, onNext, onError or onComplete MUST return normally
  12. Reactive Streams interface Subscriber<T> {
 void onNext(T t);
 void onComplete();


    void onError(Throwable t);
 void onSubscribe(Subscription s);
 }B Calling onSubscribe, onNext, onError or onComplete MUST return normally except when any provided parameter is null in which case it MUST throw a java.lang.NullPointerException to the caller
  13. Reactive Streams interface Subscriber<T> {
 void onNext(T t);
 void onComplete();


    void onError(Throwable t);
 void onSubscribe(Subscription s);
 }B Calling onSubscribe, onNext, onError or onComplete MUST return normally except when any provided parameter is null in which case it MUST throw a java.lang.NullPointerException to the caller
  14. Flowable

  15. Flowable ALL NEW!!!!!

  16. Flowable • Implementation of Reactive Streams Publisher. ALL NEW!!!!!

  17. Flowable • Implementation of Reactive Streams Publisher. • Observed with

    Reactive Streams Subscriber. ALL NEW!!!!!
  18. Flowable • Implementation of Reactive Streams Publisher. • Observed with

    Reactive Streams Subscriber. • 0 to many items, completes or errors. ALL NEW!!!!!
  19. Flowable • Implementation of Reactive Streams Publisher. • Observed with

    Reactive Streams Subscriber. • 0 to many items, completes or errors. • Handles backpressure to slow down events
 with Reactive Streams Subscription. ALL NEW!!!!!
  20. Flowable • Implementation of Reactive Streams Publisher. • Observed with

    Reactive Streams Subscriber. • 0 to many items, completes or errors. • Handles backpressure to slow down events
 with Reactive Streams Subscription. • Hundreds of convenience methods for
 transforming and composing data. ALL NEW!!!!!
  21. Flowable • Implementation of Reactive Streams Publisher. • Observed with

    Reactive Streams Subscriber. • 0 to many items, completes or errors. • Handles backpressure to slow down events
 with Reactive Streams Subscription. • Hundreds of convenience methods for
 transforming and composing data. ALL NEW!!!!!
  22. Flowable (aka RxJava 1.x's Observable) • Implementation of Reactive Streams

    Publisher. • Observed with Reactive Streams Subscriber. • 0 to many items, completes or errors. • Handles backpressure to slow down events
 with Reactive Streams Subscription. • Hundreds of convenience methods for
 transforming and composing data.
  23. FlowableProcessor

  24. FlowableProcessor ALL NEW!!!!!

  25. FlowableProcessor • Implementation of Reactive Streams Processor
 (aka Publisher via

    Flowable + Subscriber). ALL NEW!!!!!
  26. FlowableProcessor • Implementation of Reactive Streams Processor
 (aka Publisher via

    Flowable + Subscriber). ALL NEW!!!!!
  27. FlowableProcessor (aka 1.x's Subject) • Implementation of Reactive Streams Processor


    (aka Publisher via Flowable + Subscriber).
  28. Observable? Subject?

  29. Observable • Observed with an Observer (not Reactive Streams type).

    • 0 to many items, completes or errors. • No backpressure support. • Hundreds of convenience methods for transforming and
 composing data.
  30. Observable • Observed with an Observer (not Reactive Streams type).

    • 0 to many items, completes or errors. • No backpressure support. • Hundreds of convenience methods for transforming and
 composing data.
  31. Subject • Implementation of Observable and Observer.

  32. Flowable vs. Observable

  33. Flowable vs. Observable • RxJava 1.x added backpressure late in

    the design process.
  34. Flowable vs. Observable • RxJava 1.x added backpressure late in

    the design process. • All types exposed backpressure but not all sources respected it.
  35. Flowable vs. Observable • RxJava 1.x added backpressure late in

    the design process. • All types exposed backpressure but not all sources respected it. • Backpressure, like inheritance, must be designed for.
  36. Flowable vs. Observable • Backpressure, like inheritance, must be designed

    for. RxView.touches(paintView) .subscribe(e -> draw(e));
  37. Flowable vs. Observable • Backpressure, like inheritance, must be designed

    for. RxView.touches(paintView) .subscribe(e -> draw(e));
  38. Flowable vs. Observable • Backpressure, like inheritance, must be designed

    for. RxView.touches(paintView) .subscribe(e -> draw(e)); db.createQuery("SELECT * …") .subscribe(e -> update(e));
  39. Flowable vs. Observable • Backpressure, like inheritance, must be designed

    for. RxView.touches(paintView) .subscribe(e -> draw(e)); db.createQuery("SELECT * …") .subscribe(e -> update(e));
  40. Flowable vs. Observable • Backpressure, like inheritance, must be designed

    for. RxView.touches(paintView) .subscribe(e -> draw(e)); db.createQuery("SELECT * …") .subscribe(e -> update(e)); Observable<MotionEvent> Observable<Row>
  41. Flowable vs. Observable • Backpressure, like inheritance, must be designed

    for. RxView.touches(paintView) .subscribe(e -> draw(e)); db.createQuery("SELECT * …") .subscribe(e -> update(e)); Observable<MotionEvent> Observable<Row> MissingBackpressureException
  42. Flowable vs. Observable • Backpressure, like inheritance, must be designed

    for. RxView.touches(paintView) .subscribe(e -> draw(e)); db.createQuery("SELECT * …") .subscribe(e -> update(e)); Observable<MotionEvent> Flowable<Row>
  43. Flowable vs. Observable Observable<MotionEvent> Flowable<Row> interface Subscriber<T> {
 void onNext(T

    t);
 void onComplete();
 void onError(Throwable t);
 void onSubscribe(Subscription s);
 }B interface Observer<T> {
 void onNext(T t);
 void onComplete();
 void onError(Throwable t);
 void onSubscribe(Disposable d);
 }B
  44. Flowable vs. Observable Observable<MotionEvent> Flowable<Row> interface Subscriber<T> {
 void onNext(T

    t);
 void onComplete();
 void onError(Throwable t);
 void onSubscribe(Subscription s);
 }B interface Observer<T> {
 void onNext(T t);
 void onComplete();
 void onError(Throwable t);
 void onSubscribe(Disposable d);
 }B interface Disposable {
 void dispose();
 }B interface Subscription {
 void cancel();
 void request(long r);
 }B
  45. Converting

  46. Converting Observable

  47. Converting 1 2 3 4 5 6 7 8 9

    10 11 Observable
  48. Converting Observable toFlowable()X

  49. Converting Observable toFlowable(DROP)X

  50. Converting Observable toFlowable(DROP)X Flowable

  51. Converting Observable Flowable toFlowable(DROP)X request(5)

  52. Converting 1 2 3 4 5 Observable Flowable toFlowable(DROP)X 1

    2 3 4 5 request(5)
  53. Converting 1 2 3 4 5 6 7 8 Observable

    Flowable toFlowable(DROP)X 1 2 3 4 5 request(5)
  54. Converting 1 2 3 4 5 6 7 8 Observable

    Flowable toFlowable(DROP)X 1 2 3 4 5 request(5) request(2)
  55. Converting 1 2 3 4 5 6 7 8 9

    10 11 Observable Flowable toFlowable(DROP)X 1 2 3 4 5 9 10 request(5) request(2)
  56. Converting Observable toFlowable(LATEST)X Flowable

  57. Converting Observable Flowable request(5) toFlowable(LATEST)X

  58. Converting 1 2 3 4 5 Observable Flowable 1 2

    3 4 5 request(5) toFlowable(LATEST)X
  59. Converting 1 2 3 4 5 6 7 8 Observable

    Flowable 1 2 3 4 5 request(5) toFlowable(LATEST)X
  60. Converting 1 2 3 4 5 6 7 8 Observable

    Flowable 1 2 3 4 5 request(5) request(2) toFlowable(LATEST)X
  61. Converting 1 2 3 4 5 6 7 8 Observable

    Flowable 1 2 3 4 5 request(5) request(2) toFlowable(LATEST)X 8
  62. Converting 1 2 3 4 5 6 7 8 9

    10 11 Observable Flowable 1 2 3 4 5 9 request(5) request(2) toFlowable(LATEST)X 8
  63. Converting Observable BUFFER Flowable toFlowable( )X

  64. Converting Observable Flowable request(5) toFlowable(BUFFER)X

  65. Converting 1 2 3 4 5 Observable Flowable 1 2

    3 4 5 request(5) toFlowable(BUFFER)X
  66. Converting 1 2 3 4 5 6 7 8 Observable

    Flowable 1 2 3 4 5 request(5) toFlowable(BUFFER)X
  67. Converting 1 2 3 4 5 6 7 8 Observable

    Flowable 1 2 3 4 5 request(5) request(2) toFlowable(BUFFER)X
  68. Converting 1 2 3 4 5 6 7 8 Observable

    Flowable 1 2 3 4 5 request(5) request(2) toFlowable(BUFFER)X 6 7
  69. Converting 1 2 3 4 5 6 7 8 9

    10 11 Observable Flowable 1 2 3 4 5 request(5) request(2) toFlowable(BUFFER)X 6 7
  70. Converting toObservable() Observable Flowable

  71. Converting Observable Flowable request(Long.MAX_VALUE) toObservable()

  72. Converting 1 2 3 4 5 6 7 8 9

    10 11 Observable Flowable 1 2 3 4 5 request(Long.MAX_VALUE) 6 7 8 9 10 11 toObservable()
  73. Specializations

  74. Specializations • Encoding subsets of Observable into the type system.

  75. Single

  76. Single • Either succeeds with an item or errors. •

    No backpressure support. • Convenience methods for transforming and composing data.
  77. Single • Either succeeds with an item or errors. •

    No backpressure support. • Convenience methods for transforming and composing data. • Think "reactive scalar".
  78. Completable

  79. Completable • Either completes or errors. Has no items! •

    No backpressure support. • Convenience methods for transforming and composing data.
  80. Completable • Either completes or errors. Has no items! •

    No backpressure support. • Convenience methods for transforming and composing data. • Think "reactive runnable".
  81. Maybe

  82. Maybe ALL NEW!!!!!

  83. Maybe • Either succeeds with an item, completes with no

    items, or errors. • No backpressure support. • Convenience methods for transforming
 and composing data. ALL NEW!!!!!
  84. Maybe • Either succeeds with an item, completes with no

    items, or errors. • No backpressure support. • Convenience methods for transforming
 and composing data. • Think "reactive optional". ALL NEW!!!!!
  85. Specializations • Encoding subsets of Observable into the type system.

    • Single – Item or error. Think "scalar". • Completable – Complete or error. Think "runnable". • Maybe – Item, complete, or error. Think "optional".
  86. Backpressure
 & Reactive Streams No Backpressure 0…n items, complete|error Flowable

    Observable item|complete|error Maybe item|error Single complete|error Completable Multicast FlowableProcessor Subject
  87. Operator Specialization

  88. Operator Specialization first() Observable

  89. Operator Specialization first() Observable Observable

  90. Operator Specialization 1 2 3 4 5 6 7 8

    9 10 11 first() 1 Observable Observable
  91. Operator Specialization first() Observable Single

  92. Operator Specialization 1 2 3 4 5 6 7 8

    9 10 11 first() 1 Observable Single
  93. Operator Specialization first() Observable Single NoSuchElementException

  94. Operator Specialization firstElement() Observable

  95. Operator Specialization firstElement() Observable Maybe

  96. Operator Specialization firstElement() Observable Maybe

  97. Operator Specialization ignoreElements() Observable

  98. Operator Specialization ignoreElements() Observable Completable

  99. Operator Specialization 1 2 3 4 5 6 7 8

    9 ignoreElements() Observable Completable
  100. Operator Specialization ignoreElements() Flowable Completable

  101. Operator Specialization 1 2 3 4 5 6 7 8

    9 ignoreElements() Flowable Completable
  102. Operator Specialization firstElement() Flowable Maybe

  103. Operator Specialization first() Flowable Single

  104. Flowable Observable Maybe Single Completable Flowable toObservable() reduce() elementAt() firstElement()

    lastElement() singleElement() scan() elementAt() first()/firstOrError() last()/lastOrError() single/singleOrError() all()/any()/count() (and more) ignoreElements() Observable toFlowable() reduce() elementAt() firstElement() lastElement() singleElement() scan() elementAt() first()/firstOrError() last()/lastOrError() single/singleOrError() all()/any()/count() (and more) ignoreElements() Maybe toFlowable() toObservable() toSingle() sequenceEqual() toCompletable() Single toFlowable() toObservable() toMaybe() toCompletable() Completable toFlowable() toObservable() toMaybe() toSingle() toSingleDefault() From To
  105. Flowable Observable Maybe Single Completable Flowable toObservable() reduce() elementAt() firstElement()

    lastElement() singleElement() scan() elementAt() first()/firstOrError() last()/lastOrError() single/singleOrError() all()/any()/count() (and more) ignoreElements() Observable toFlowable() reduce() elementAt() firstElement() lastElement() singleElement() scan() elementAt() first()/firstOrError() last()/lastOrError() single/singleOrError() all()/any()/count() (and more) ignoreElements() Maybe toFlowable() toObservable() toSingle() sequenceEqual() toCompletable() Single toFlowable() toObservable() toMaybe() toCompletable() Completable toFlowable() toObservable() toMaybe() toSingle() toSingleDefault() From To
  106. Flowable Observable Maybe Single Completable Flowable toObservable() reduce() elementAt() firstElement()

    lastElement() singleElement() scan() elementAt() first()/firstOrError() last()/lastOrError() single/singleOrError() all()/any()/count() (and more) ignoreElements() Observable toFlowable() reduce() elementAt() firstElement() lastElement() singleElement() scan() elementAt() first()/firstOrError() last()/lastOrError() single/singleOrError() all()/any()/count() (and more) ignoreElements() Maybe toFlowable() toObservable() toSingle() sequenceEqual() toCompletable() Single toFlowable() toObservable() toMaybe() toCompletable() Completable toFlowable() toObservable() toMaybe() toSingle() toSingleDefault() From To
  107. Creating Sources

  108. Creating Sources Flowable.just("Hello");
 Flowable.just("Hello", "World"); 
 Observable.just("Hello");
 Observable.just("Hello", "World");
 Maybe.just("Hello");


    Single.just("Hello");
  109. Creating Sources String[] array = { "Hello", "World" };
 List<String>

    list = Arrays.asList(array);
 Flowable.fromArray(array); Flowable.fromIterable(list); Observable.fromArray(array); Observable.fromIterable(list);
  110. Creating Sources Future<String> future = CompletableFuture.completedFuture("Hello");
 Flowable.fromFuture(future);
 Observable.fromFuture(future);

  111. Creating Sources Flowable.empty();
 
 Observable.empty();
 
 Maybe.empty();
 
 Completable.complete();

  112. Creating Sources Flowable.never();
 
 Observable.never();
 
 Maybe.never(); Single.never();
 
 Completable.never();

  113. Creating Sources Flowable.error(new RuntimeException());
 Observable.error(new RuntimeException());
 Maybe.error(new RuntimeException());
 Single.error(new RuntimeException());


    Completable.error(new RuntimeException());
  114. Creating Sources Observable.fromCallable(new Callable<String>() {
 @Override public String call() {Y


    return getName();
 }X
 });
  115. Creating Sources Observable.fromCallable(new Callable<String>() {
 @Override public String call() throws

    Exception {Y
 return getName();Z
 }X
 });
  116. Creating Sources OkHttpClient client = // … Request request =

    // … Observable.fromCallable(new Callable<String>() {
 @Override public String call() throws Exception {Y
 return client.newCall(request).execute();Z
 }X
 }); 
 
 getName()
  117. Creating Sources Flowable.fromCallable(() -> "Hello");
 
 Observable.fromCallable(() -> "Hello");
 


    Maybe.fromCallable(() -> "Hello");
 Maybe.fromAction(() -> System.out.println("Hello"));
 Maybe.fromRunnable(() -> System.out.println("Hello"))
 
 Single.fromCallable(() -> "Hello");
 
 Completable.fromCallable(() -> "Ignored!");
 Completable.fromAction(() -> System.out.println("Hello"));
 Completable.fromRunnable(() -> System.out.println("Hello"));
  118. Creating Sources Observable.create();

  119. Creating Sources Observable.create(); 100% LESS AWFUL!!!

  120. Creating Sources Observable.create(new ObservableOnSubscribe<String>() {
 @Override
 public void subscribe(ObservableEmitter<String> e)

    throws Exception {
 e.onNext("Hello");
 e.onComplete();
 }X
 });
  121. Creating Sources Observable.create(new ObservableOnSubscribe<String>() {
 @Override
 public void subscribe(ObservableEmitter<String> e)

    throws Exception {
 e.onNext("Hello");
 e.onComplete();
 }X
 });
  122. Creating Sources Observable.create(new ObservableOnSubscribe<String>() {
 @Override
 public void subscribe(ObservableEmitter<String> e)

    throws Exception {
 e.onNext("Hello");
 e.onComplete();
 }X
 });
  123. Creating Sources Observable.create(e -> {
 e.onNext("Hello");
 e.onComplete();
 }); new ObservableOnSubscribe<String>()


    @Override
 public void subscribe(ObservableEmitter<String> ) throws Exception {
 
 
 }X

  124. Creating Sources Observable.create(e -> {
 e.onNext("Hello"); e.onNext("World");
 e.onComplete();
 });

  125. Creating Sources OkHttpClient client = // … Request request =

    // … Observable.create(e -> { client.newCall(request).enqueue(new Callback() { @Override public void onResponse(Response r) throws IOException { e.onNext(r.body().string()); e.onComplete(); }A @Override public void onFailure(IOException e) { e.onError(e); }B });
 }); 
 e.onNext("Hello"); e.onNext("World");
 e.onComplete();
  126. Creating Sources OkHttpClient client = // … Request request =

    // … Observable.create(e -> { Call call = client.newCall(request); call.enqueue(new Callback() { @Override public void onResponse(Response r) throws IOException { e.onNext(r.body().string()); e.onComplete(); }A @Override public void onFailure(IOException e) { e.onError(e); }B });
 });
  127. Creating Sources OkHttpClient client = // … Request request =

    // … Observable.create(e -> { Call call = client.newCall(request); e.setCancelation(() -> call.cancel()); call.enqueue(new Callback() { @Override public void onResponse(Response r) throws IOException { e.onNext(r.body().string()); e.onComplete(); }A @Override public void onFailure(IOException e) { e.onError(e); }B });
 });
  128. Creating Sources OkHttpClient client = // … Request request =

    // … Observable.create(e -> { Call call = client.newCall(request); e.setCancelation(() -> call.cancel()); call.enqueue(new Callback() { @Override public void onResponse(Response r) throws IOException { e.onNext(r.body().string()); e.onComplete(); }A @Override public void onFailure(IOException e) { e.onError(e); }B });
 });
  129. Creating Sources View view = // … Observable.create(e -> {

    e.setCancelation(() -> view.setOnClickListener(null)); view.setOnClickListener(v -> e.onNext(v));
 }); OkHttpClient client = // ... Request request = // ... Call call = client.newCall(request); e.setCancelation(() -> call.cancel()); call.enqueue(new Callback() { @Override public void onResponse(Response r) throws IOException { e.onNext(r.body().string()); e.onComplete(); }A @Override public void onFailure(IOException e) { e.onError(e); }B });

  130. Creating Sources Flowable.create(e -> { … }); Observable.create(e -> {

    … }); Maybe.create(e -> { … }); Single.create(e -> { … }); Completable.create(e -> { … });
  131. Observing Sources

  132. Observing Sources Observable<String> Flowable<String> interface Subscriber<T> {
 void onNext(T t);


    void onComplete();
 void onError(Throwable t);
 void onSubscribe(Subscription s);
 }B interface Observer<T> {
 void onNext(T t);
 void onComplete();
 void onError(Throwable t);
 void onSubscribe(Disposable d);
 }B
  133. Observing Sources Observable<String> Flowable<String> interface Subscriber<T> {
 void onNext(T t);


    void onComplete();
 void onError(Throwable t);
 void onSubscribe(Subscription s);
 }B interface Observer<T> {
 void onNext(T t);A
 void onComplete();B
 void onError(Throwable t);C
 void onSubscribe(Disposable d);D
 }B interface Disposable {
 void dispose();
 }B interface Subscription {
 void cancel();
 void request(long r);
 }B
  134. Observing Sources Observable<String> o = Observable.just("Hello"); o.subscribe(new Observer<String>() {
 @Override

    public void onNext(String s) { … }
 @Override public void onComplete() { … }
 @Override public void onError(Throwable t) { … } 
 @Override public void onSubscribe(Disposable d) { ??? }B
 }); Flowable<String> interface Subscriber<T> {
 void onNext(T t);
 void onComplete();
 void onError(Throwable t);
 void onSubscribe(Subscription s);
 }B interface Disposable {
 void dispose();
 }B interface Subscription {
 void cancel();
 void request(long r);
 }B interface T
 T t ;A
 ;B
 ;C
 ;D

  135. Observing Sources Observable<String> o = Observable.just("Hello"); o.subscribe(new DisposableObserver<String>() {
 @Override

    public void onNext(String s) { … }
 @Override public void onComplete() { … }
 @Override public void onError(Throwable t) { … }
 }); 
 
 
 
 @Override public void onSubscribe(Disposable d) { ??? }B

  136. Observing Sources Observable<String> o = Observable.just("Hello"); o.subscribe(new DisposableObserver<String>() {
 @Override

    public void onNext(String s) { … }
 @Override public void onComplete() { … }
 @Override public void onError(Throwable t) { … }
 });Z unsubscribe???
  137. Observing Sources Observable<String> o = Observable.just("Hello"); DisposableObserver observer = new

    DisposableObserver<String>() {
 @Override public void onNext(String s) { … }
 @Override public void onComplete() { … }
 @Override public void onError(Throwable t) { … }
 } o.subscribe(observer);Z unsubscribe???
  138. Observing Sources Observable<String> o = Observable.just("Hello"); DisposableObserver observer = new

    DisposableObserver<String>() {
 @Override public void onNext(String s) { … }
 @Override public void onComplete() { … }
 @Override public void onError(Throwable t) { … }
 } o.subscribe(observer);Z observer.dispose();
  139. Observing Sources Observable<String> o = Observable.just("Hello"); o.subscribe(new DisposableObserver<String>() {
 @Override

    public void onNext(String s) { … }
 @Override public void onComplete() { … }
 @Override public void onError(Throwable t) { … }
 });Z
  140. Observing Sources Observable<String> o = Observable.just("Hello"); o.subscribeWith(new DisposableObserver<String>() {
 @Override

    public void onNext(String s) { … }
 @Override public void onComplete() { … }
 @Override public void onError(Throwable t) { … }
 });Z
  141. Observing Sources Observable<String> o = Observable.just("Hello"); Disposable d = o.subscribeWith(new

    DisposableObserver<String>() {
 @Override public void onNext(String s) { … }
 @Override public void onComplete() { … }
 @Override public void onError(Throwable t) { … }
 });Z d.dispose();
  142. Observing Sources Observable<String> o = Observable.just("Hello"); CompositeDisposable disposables = new

    CompositeDisposable(); Disposable d = o.subscribeWith(new DisposableObserver<String>() {
 @Override public void onNext(String s) { … }
 @Override public void onComplete() { … }
 @Override public void onError(Throwable t) { … }
 });Z disposables.add(d); 
 
 
 
 d.dispose();
  143. Observing Sources Observable<String> o = Observable.just("Hello"); CompositeDisposable disposables = new

    CompositeDisposable(); Disposable d = o.subscribeWith(new DisposableObserver<String>() {
 @Override public void onNext(String s) { … }
 @Override public void onComplete() { … }
 @Override public void onError(Throwable t) { … }
 });Z disposables.add(d); disposables.dispose();
  144. Observing Sources Observable<String> o = Observable.just("Hello"); o.subscribeWith(new DisposableObserver<String>() { …

    });Z Maybe<String> m = Maybe.just("Hello"); m.subscribeWith(new DisposableMaybeObserver<String>() { … });Z Single<String> s = Single.just("Hello"); s.subscribeWith(new DisposableSingleObserver<String>() { … });Z Completable c = Completable.completed(); c.subscribeWith(new DisposableCompletableObserver<String>() { … });Z
  145. Observing Sources Flowable<String> f = Flowable.just("Hello"); f.subscribeWith(new DisposableSubscriber<String>() { …

    }); Observable<String> o = Observable.just("Hello"); o.subscribeWith(new DisposableObserver<String>() { … }); Maybe<String> m = Maybe.just("Hello"); m.subscribeWith(new DisposableMaybeObserver<String>() { … }); Single<String> s = Single.just("Hello"); s.subscribeWith(new DisposableSingleObserver<String>() { … }); Completable c = Completable.completed(); c.subscribeWith(new DisposableCompletableObserver<String>() { … });
  146. Observing Sources Flowable<String> f = Flowable.just("Hello"); f.subscribeWith(new DisposableSubscriber<String>() { …

    }); Observable<String> o = Observable.just("Hello"); o.subscribeWith(new DisposableObserver<String>() { … }); Maybe<String> m = Maybe.just("Hello"); m.subscribeWith(new DisposableMaybeObserver<String>() { … }); Single<String> s = Single.just("Hello"); s.subscribeWith(new DisposableSingleObserver<String>() { … }); Completable c = Completable.completed(); c.subscribeWith(new DisposableCompletableObserver<String>() { … });
  147. Observing Sources Flowable<String> f = Flowable.just("Hello"); Disposable d1 = f.subscribeWith(new

    DisposableSubscriber<String>() { … }); Observable<String> o = Observable.just("Hello"); Disposable d2 = o.subscribeWith(new DisposableObserver<String>() { … }); Maybe<String> m = Maybe.just("Hello"); Disposable d3 = m.subscribeWith(new DisposableMaybeObserver<String>() { … }); Single<String> s = Single.just("Hello"); Disposable d4 = s.subscribeWith(new DisposableSingleObserver<String>() { … }); Completable c = Completable.completed(); Disposable d5 = c.subscribeWith(new DisposableCompletableObserver<String>() { … });
  148. RxJava

  149. RxJava • 2.0.0-RC3 was released 2016-09-23.

  150. RxJava • 2.0.0-RC3 was released 2016-09-23. • Releases are more

    like developer previews than release candidates.
  151. RxJava • 2.0.0-RC3 was released 2016-09-23. • Releases are more

    like developer previews than release candidates. • Next two are scheduled for 2016-10-07 and 2016-10-21.
  152. RxJava • 2.0.0-RC3 was released 2016-09-23. • Releases are more

    like developer previews than release candidates. • Next two are scheduled for 2016-10-07 and 2016-10-21. • Final release scheduled for 2016-10-29.
  153. RxJava • Package name is io.reactivex.*.

  154. RxJava • Package name is io.reactivex.*. • Maven coordinates are

    io.reactivex.rxjava2:rxjava.
  155. RxJava • Package name is io.reactivex.*. • Maven coordinates are

    io.reactivex.rxjava2:rxjava. • Why the change? See http://jakes.link/major-versions
  156. RxAndroid

  157. RxAndroid • 2.0.0-RC1 was released 2016-08-25.

  158. RxAndroid • 2.0.0-RC1 was released 2016-08-25. • Provides facilities for

    dealing with the main thread (or any Looper).
  159. RxAndroid • 2.0.0-RC1 was released 2016-08-25. • Provides facilities for

    dealing with the main thread (or any Looper). • Package name is io.reactivex.android.*.
  160. RxAndroid • 2.0.0-RC1 was released 2016-08-25. • Provides facilities for

    dealing with the main thread (or any Looper). • Package name is io.reactivex.android.*. • Maven coordinates are io.reactivex.rxjava2:rxandroid.
  161. Living with 1.x and 2.x

  162. Living with 1.x and 2.x class RxJavaInterop {
 static <T>

    Flowable<T> toV2Flowable(rx.Observable<T> o) { … }
 static <T> Observable<T> toV2Observable(rx.Observable<T> o) { … } static <T> Maybe<T> toV2Maybe(rx.Single<T> s) { … } static <T> Maybe<T> toV2Maybe(rx.Completable c) { … }
 static <T> Single<T> toV2Single(rx.Single<T> s) { … }
 static Completable toV2Completable(rx.Completable c) { … } 
 static <T> rx.Observable<T> toV1Observable(Publisher<T> p) { … } static <T> rx.Observable<T> toV1Observable(Observable<T> o, …) { … }
 static <T> rx.Single<T> toV1Single(Single<T> o) { … } static <T> rx.Single<T> toV1Single(Maybe<T> m) { … }
 static rx.Completable toV1Completable(Completable c) { … } static rx.Completable toV1Completable(Maybe<T> m) { … }
 }X
  163. Living with 1.x and 2.x class RxJavaInterop {
 static <T>

    Flowable<T> toV2Flowable(rx.Observable<T> o) { … }
 static <T> Observable<T> toV2Observable(rx.Observable<T> o) { … } static <T> Maybe<T> toV2Maybe(rx.Single<T> s) { … } static <T> Maybe<T> toV2Maybe(rx.Completable c) { … }
 static <T> Single<T> toV2Single(rx.Single<T> s) { … }
 static Completable toV2Completable(rx.Completable c) { … } 
 static <T> rx.Observable<T> toV1Observable(Publisher<T> p) { … } static <T> rx.Observable<T> toV1Observable(Observable<T> o, …) { … }
 static <T> rx.Single<T> toV1Single(Single<T> o) { … } github.com/akarnokd/RxJava2Interop
  164. dependencies {
 compile 'io.reactivex.rxjava2:rxjava:2.0.0-RC3'
 compile 'io.reactivex.rxjava2:rxandroid:2.0.0-RC1' // Optionally...
 compile 'com.github.akarnokd:rxjava2-interop:0.3.0'

    }
  165. Other Libraries We Control

  166. Other Libraries We Control • Retrofit 2 – github.com/JakeWharton/retrofit2-rxjava2-adapter/

  167. Other Libraries We Control • Retrofit 2 – github.com/JakeWharton/retrofit2-rxjava2-adapter/ •

    RxBinding – waiting for 2.0 final • RxRelay – waiting for 2.0 final • RxReplayingShare – waiting for 2.0 final • SQL Brite – waiting for 2.0 final • Whorlwind – waiting for 2.0 final
  168. RxJava 2

  169. RxJava 2 • Reactive Streams compliant.

  170. RxJava 2 • Reactive Streams compliant. • Backpressure in the

    type system (Flowable).
  171. RxJava 2 • Reactive Streams compliant. • Backpressure in the

    type system (Flowable). • New Maybe type.
  172. RxJava 2 • Reactive Streams compliant. • Backpressure in the

    type system (Flowable). • New Maybe type. • Actually usable create().
  173. RxJava 2 • Reactive Streams compliant. • Backpressure in the

    type system (Flowable). • New Maybe type. • Actually usable create(). • All the same operators.
  174. RxJava 2 • Reactive Streams compliant. • Backpressure in the

    type system (Flowable). • New Maybe type. • Actually usable create(). • All the same operators. • Preview releases now, final release in a month.
  175. jakewharton jakewharton jakewharton twitter.com/ google.com/+ .com Looking Ahead To 


    RxJava 2