use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class FlowableConcatWithCompletableTest method mainError.
@Test
public void mainError() {
final TestSubscriber<Integer> ts = new TestSubscriber<>();
Flowable.<Integer>error(new TestException()).concatWith(Completable.fromAction(new Action() {
@Override
public void run() throws Exception {
ts.onNext(100);
}
})).subscribe(ts);
ts.assertFailure(TestException.class);
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class ObservableRetryTest method noCancelPreviousRetryWhile.
@Test
public void noCancelPreviousRetryWhile() {
final AtomicInteger counter = new AtomicInteger();
final AtomicInteger times = new AtomicInteger();
Observable<Integer> source = Observable.defer(new Supplier<ObservableSource<Integer>>() {
@Override
public ObservableSource<Integer> get() throws Exception {
if (times.getAndIncrement() < 4) {
return Observable.error(new TestException());
}
return Observable.just(1);
}
}).doOnDispose(new Action() {
@Override
public void run() throws Exception {
counter.getAndIncrement();
}
});
source.retry(5, Functions.alwaysTrue()).test().assertResult(1);
assertEquals(0, counter.get());
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class ObservableRetryTest method noCancelPreviousRetryWhile2.
@Test
public void noCancelPreviousRetryWhile2() {
final AtomicInteger counter = new AtomicInteger();
final AtomicInteger times = new AtomicInteger();
Observable<Integer> source = Observable.defer(new Supplier<ObservableSource<Integer>>() {
@Override
public ObservableSource<Integer> get() throws Exception {
if (times.getAndIncrement() < 4) {
return Observable.error(new TestException());
}
return Observable.just(1);
}
}).doOnDispose(new Action() {
@Override
public void run() throws Exception {
counter.getAndIncrement();
}
});
source.retry(new BiPredicate<Integer, Throwable>() {
@Override
public boolean test(Integer a, Throwable b) throws Exception {
return a < 5;
}
}).test().assertResult(1);
assertEquals(0, counter.get());
}
use of io.reactivex.rxjava3.functions.Action in project RxPermissions by tbruyelle.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RxPermissions rxPermissions = new RxPermissions(this);
rxPermissions.setLogging(true);
setContentView(R.layout.act_main);
surfaceView = findViewById(R.id.surfaceView);
disposable = RxView.clicks(findViewById(R.id.enableCamera)).compose(rxPermissions.ensureEach(permission.CAMERA)).subscribe(new Consumer<Permission>() {
@Override
public void accept(Permission permission) {
Log.i(TAG, "Permission result " + permission);
if (permission.granted) {
releaseCamera();
camera = Camera.open(0);
try {
camera.setPreviewDisplay(surfaceView.getHolder());
camera.startPreview();
} catch (IOException e) {
Log.e(TAG, "Error while trying to display the camera preview", e);
}
} else if (permission.shouldShowRequestPermissionRationale) {
// Denied permission without ask never again
Toast.makeText(MainActivity.this, "Denied permission without ask never again", Toast.LENGTH_SHORT).show();
} else {
// Denied permission with ask never again
// Need to go to the settings
Toast.makeText(MainActivity.this, "Permission denied, can't enable the camera", Toast.LENGTH_SHORT).show();
}
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable t) {
Log.e(TAG, "onError", t);
}
}, new Action() {
@Override
public void run() {
Log.i(TAG, "OnComplete");
}
});
}
use of io.reactivex.rxjava3.functions.Action in project redisson by redisson.
the class PublisherAdder method addAll.
public Single<Boolean> addAll(Publisher<? extends V> c) {
final Flowable<? extends V> cc = Flowable.fromPublisher(c);
final ReplayProcessor<Boolean> p = ReplayProcessor.create();
return p.doOnRequest(new LongConsumer() {
@Override
public void accept(long t) throws Exception {
final AtomicBoolean completed = new AtomicBoolean();
final AtomicLong values = new AtomicLong();
final AtomicBoolean lastSize = new AtomicBoolean();
cc.subscribe(new Consumer<V>() {
@Override
public void accept(V t) throws Exception {
values.getAndIncrement();
add(t).whenComplete((res, e) -> {
if (e != null) {
p.onError(e);
return;
}
if (res) {
lastSize.set(true);
}
if (values.decrementAndGet() == 0 && completed.get()) {
p.onNext(lastSize.get());
p.onComplete();
}
});
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable t) throws Exception {
p.onError(t);
}
}, new Action() {
@Override
public void run() throws Exception {
completed.set(true);
if (values.get() == 0) {
p.onNext(lastSize.get());
p.onComplete();
}
}
});
}
}).singleOrError();
}
Aggregations