当前位置: 首页>>代码示例>>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;未经允许,请勿转载。