本文整理汇总了Java中io.reactivex.subjects.AsyncSubject类的典型用法代码示例。如果您正苦于以下问题:Java AsyncSubject类的具体用法?Java AsyncSubject怎么用?Java AsyncSubject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AsyncSubject类属于io.reactivex.subjects包,在下文中一共展示了AsyncSubject类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: main
import io.reactivex.subjects.AsyncSubject; //导入依赖的package包/类
public static void main(String[] args) {
Subject<String> subject =
AsyncSubject.create();
subject.subscribe(s ->
System.out.println("Observer 1: " + s),
Throwable::printStackTrace,
() -> System.out.println("Observer 1 done!")
);
subject.onNext("Alpha");
subject.onNext("Beta");
subject.onNext("Gamma");
subject.onComplete();
subject.subscribe(s ->
System.out.println("Observer 2: " + s),
Throwable::printStackTrace,
() -> System.out.println("Observer 2 done!")
);
}
开发者ID:PacktPublishing,项目名称:Learning-RxJava,代码行数:19,代码来源:Ch5_25.java
示例2: doSomeWork
import io.reactivex.subjects.AsyncSubject; //导入依赖的package包/类
private void doSomeWork(int type) {
AsyncSubject<Integer> source = AsyncSubject.create();
source.subscribe(getFirstObserver()); // it will emit only 4 and onComplete
source.onNext(1);
source.onNext(2);
source.onNext(3);
/*
* it will emit 4 and onComplete for second observer also.
*/
source.subscribe(getSecondObserver());
source.onNext(4);
if (type==COMPLETE){
source.onComplete();
}
if (type==ERROR){
source.onError(new Exception("test send onError"));
}
}
开发者ID:changjiashuai,项目名称:RxJava2-Android-Sample,代码行数:24,代码来源:AsyncSubjectExampleActivity.java
示例3: requestPermission
import io.reactivex.subjects.AsyncSubject; //导入依赖的package包/类
/**main function request for permission. If Completable completes permission is granted.
* Otherwise error is emitted.
*/
public List<Completable> requestPermission(@NotNull Activity activity, @NotNull String permissions[]) {
List<Completable> completables = new ArrayList<>();
List<String> permissionsResult = new ArrayList<>();
for (String permission: permissions) {
AsyncSubject<Void> observable = AsyncSubject.create();
if (ContextCompat.checkSelfPermission(activity, permission)
!= PackageManager.PERMISSION_GRANTED) {
permissionsResult.add(permission);
observables.put(permission, observable);
completables.add(Completable.fromObservable(observable));
} else {
completables.add(Completable.complete());
}
}
ActivityCompat.requestPermissions(activity,
permissionsResult.toArray(new String[permissionsResult.size()]), PERMISSION_REQUEST);
return completables;
}
开发者ID:Webtrekk,项目名称:webtrekk-android-sdk,代码行数:26,代码来源:PermissionRequest.java
示例4: processResponse
import io.reactivex.subjects.AsyncSubject; //导入依赖的package包/类
public void processResponse(int requestCode,
@NotNull String permissions[], @NotNull int[] grantResults) {
switch (requestCode) {
case PERMISSION_REQUEST: {
for (int i = 0; i< grantResults.length; i++){
final AsyncSubject<Void> observable = observables.get(permissions[i]);
if (observable == null){
continue;
}
if (grantResults[i] == PackageManager.PERMISSION_GRANTED){
observable.onComplete();
} else {
observable.onError(new SecurityException());
}
}
}
}
}
开发者ID:Webtrekk,项目名称:webtrekk-android-sdk,代码行数:22,代码来源:PermissionRequest.java
示例5: testAsyncSubjectSubscribeAfterComplete
import io.reactivex.subjects.AsyncSubject; //导入依赖的package包/类
@Test
public void testAsyncSubjectSubscribeAfterComplete() {
// create an async subject, subscribe pre, and pump test through
AsyncSubject<String> testSubject = AsyncSubject.create();
RxAsserter<String> preObserver = RxAsserter.on(testSubject);
testSubject.onNext("test");
// make sure that no one has observed anything yet
preObserver.assertValues();
// when the subject completes, pre should observe but not post
testSubject.onComplete();
preObserver.assertValues("test");
// and if we subscribe after the fact, everyone should get it
RxAsserter<String> postObserver = RxAsserter.on(testSubject);
preObserver.assertValues("test");
postObserver.assertValues("test");
}
开发者ID:diffplug,项目名称:durian-rx,代码行数:20,代码来源:RxAndListenableFutureSemantics.java
示例6: main
import io.reactivex.subjects.AsyncSubject; //导入依赖的package包/类
public static void main(String[] args) {
// TODO Auto-generated method stub
AsyncSubject<Long> asyncSubject=AsyncSubject.create();
asyncSubject.subscribe(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");
}
});
asyncSubject.onNext(1L);
asyncSubject.onNext(2L);
asyncSubject.onNext(10L);
asyncSubject.onComplete();
}
开发者ID:PacktPublishing,项目名称:Reactive-Programming-With-Java-9,代码行数:41,代码来源:Demo_AsyncSubject.java
示例7: fromFuture
import io.reactivex.subjects.AsyncSubject; //导入依赖的package包/类
/**
* Create a Observable that signals the terminal value or error of the given
* CompletionStage.
* <p>Cancelling the Observable subscription doesn't cancel the CompletionStage.
* @param <T> the value type
* @param cs the CompletionStage instance
* @return the new Observable instance
*/
public static <T> Observable<T> fromFuture(CompletionStage<T> cs) {
AsyncSubject<T> ap = AsyncSubject.create();
cs.whenComplete((v, e) -> {
if (e != null) {
ap.onError(e);
} else {
ap.onNext(v);
ap.onComplete();
}
});
return ap;
}
开发者ID:akarnokd,项目名称:RxJava2Jdk8Interop,代码行数:21,代码来源:ObservableInterop.java
示例8: doSomeWork
import io.reactivex.subjects.AsyncSubject; //导入依赖的package包/类
private void doSomeWork() {
AsyncSubject<Integer> source = AsyncSubject.create();
source.subscribe(getFirstObserver()); // it will emit only 4 and onComplete
source.onNext(1);
source.onNext(2);
source.onNext(3);
/*
* it will emit 4 and onComplete for second observer also.
*/
source.subscribe(getSecondObserver());
source.onNext(4);
source.onComplete();
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:AsyncSubjectExampleActivity.java
示例9: demo5
import io.reactivex.subjects.AsyncSubject; //导入依赖的package包/类
private static void demo5() throws InterruptedException {
Subject<String> subject = AsyncSubject.create();
Observable.interval(0, 1, TimeUnit.SECONDS)
.take(4)
.map(Objects::toString)
.subscribe(subject);
subject.subscribe(v -> log(v));
Thread.sleep(5100);
subject.subscribe(v -> log(v));
}
开发者ID:PacktPublishing,项目名称:Reactive-Android-Programming,代码行数:16,代码来源:Sandbox.java
注:本文中的io.reactivex.subjects.AsyncSubject类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论