本文整理汇总了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();
}
示例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();
}
示例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();
}