RxJava源碼解讀

Observable<String> observable = Observable.just("hello world");
Consumer<String> consumer2 = new Consumer<String>(){
    @Override
    public void accept(String s) throws Exception {
       System.out.println("Test1" + s);
    }
};
observable.subscribe(consumer2);

咱們從最簡單的一段代碼入手()ide

Observable.just

clipboard.png

實際上just方法就是返回了一個ObservableJustspa

ObservableJust

clipboard.png

Observable.subscribe

clipboard.png

建立了一個LambdaObserver觀察者code

LambdaObserver

clipboard.png
主要有onSubscribe,onNext,onError,onComplete方法對應的執行的邏輯是對應的是類構造參數的回調接口server

clipboard.png
調用了ObservableJust.subscribeActual入參是LambdaObserver
clipboard.png
建立了一個ScalarDisposable接口

ScalarDisposable

clipboard.png
先會調用LambdaObserveronSubscribe而後調用ScalarDisposable.run根據上圖其實就是調用LambdaObserver.onNextip

相關文章
相關標籤/搜索