當前位置: 首頁>>代碼示例>>Java>>正文


Java BehaviorSubject.onComplete方法代碼示例

本文整理匯總了Java中io.reactivex.subjects.BehaviorSubject.onComplete方法的典型用法代碼示例。如果您正苦於以下問題:Java BehaviorSubject.onComplete方法的具體用法?Java BehaviorSubject.onComplete怎麽用?Java BehaviorSubject.onComplete使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.reactivex.subjects.BehaviorSubject的用法示例。


在下文中一共展示了BehaviorSubject.onComplete方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doSomeWork

import io.reactivex.subjects.BehaviorSubject; //導入方法依賴的package包/類
/**
 * 當觀察者訂閱BehaviorSubject時,它開始發射原始Observable最近發射的數據
 * (如果此時還 沒有收到任何數據,它會發射一個默認值),然後繼續發射其它任何來自原始Observable的數據。
 * 然而,如果原始的Observable因為發生了一個錯誤而終止,BehaviorSubject將不會發射任何數據,隻是簡單的向前傳遞這個錯誤通知。
 */
private void doSomeWork() {

    BehaviorSubject<Integer> source = BehaviorSubject.create();

    source.subscribe(getFirstObserver()); // it will get 1, 2, 3, 4 and onComplete

    source.onNext(1);
    source.onNext(2);
    source.onNext(3);

    /*
     * it will emit 3(last emitted), 4 and onComplete for second observer also.
     */
    source.subscribe(getSecondObserver());

    source.onNext(4);
    source.onComplete();

}
 
開發者ID:changjiashuai,項目名稱:RxJava2-Android-Sample,代碼行數:25,代碼來源:BehaviorSubjectExampleActivity.java

示例2: doSomeWork

import io.reactivex.subjects.BehaviorSubject; //導入方法依賴的package包/類
private void doSomeWork() {

        BehaviorSubject<Integer> source = BehaviorSubject.create();

        source.subscribe(getFirstObserver()); // it will get 1, 2, 3, 4 and onComplete

        source.onNext(1);
        source.onNext(2);
        source.onNext(3);

        /*
         * it will emit 3(last emitted), 4 and onComplete for second observer also.
         */
        source.subscribe(getSecondObserver());

        source.onNext(4);
        source.onComplete();

    }
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:20,代碼來源:BehaviorSubjectExampleActivity.java

示例3: main

import io.reactivex.subjects.BehaviorSubject; //導入方法依賴的package包/類
public static void main(String[] args) {
	// TODO Auto-generated method stub
	Observer<Long> observer=new Observer<Long>() {

		@Override
		public void onComplete() {
			// TODO Auto-generated method stub
			System.out.println("It's Done");
			
		}

		@Override
		public void onError(Throwable throwable) {
			// TODO Auto-generated method stub
			throwable.printStackTrace();
			
		}

		@Override
		public void onNext(Long value) {
			// TODO Auto-generated method stub
			System.out.println(":"+value);
		}

		@Override
		public void onSubscribe(Disposable disposable) {
			// TODO Auto-generated method stub
			System.out.println("onSubscribe");
			
		}
	};
	BehaviorSubject<Long> behaviorSubject=BehaviorSubject.create();
	behaviorSubject.onNext(1L);
	behaviorSubject.onNext(2L);
	behaviorSubject.onNext(10L);

	behaviorSubject.onError(new Exception("You got an Exception"));
	behaviorSubject.subscribe(observer);
	behaviorSubject.onComplete();

}
 
開發者ID:PacktPublishing,項目名稱:Reactive-Programming-With-Java-9,代碼行數:42,代碼來源:Demo_BehaviorSubject.java


注:本文中的io.reactivex.subjects.BehaviorSubject.onComplete方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。