use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class ObservableRepeatTest method noCancelPreviousRepeatUntil.
@Test
public void noCancelPreviousRepeatUntil() {
final AtomicInteger counter = new AtomicInteger();
Observable<Integer> source = Observable.just(1).doOnDispose(new Action() {
@Override
public void run() throws Exception {
counter.getAndIncrement();
}
});
final AtomicInteger times = new AtomicInteger();
source.repeatUntil(new BooleanSupplier() {
@Override
public boolean getAsBoolean() throws Exception {
return times.getAndIncrement() == 4;
}
}).test().assertResult(1, 1, 1, 1, 1);
assertEquals(0, counter.get());
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class ObservableRepeatTest method noCancelPreviousRepeatWhen.
@Test
public void noCancelPreviousRepeatWhen() {
final AtomicInteger counter = new AtomicInteger();
Observable<Integer> source = Observable.just(1).doOnDispose(new Action() {
@Override
public void run() throws Exception {
counter.getAndIncrement();
}
});
final AtomicInteger times = new AtomicInteger();
source.repeatWhen(new Function<Observable<Object>, ObservableSource<?>>() {
@Override
public ObservableSource<?> apply(Observable<Object> e) throws Exception {
return e.takeWhile(new Predicate<Object>() {
@Override
public boolean test(Object v) throws Exception {
return times.getAndIncrement() < 4;
}
});
}
}).test().assertResult(1, 1, 1, 1, 1);
assertEquals(0, counter.get());
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class ObservableMergeWithCompletableTest method normal.
@Test
public void normal() {
final TestObserver<Integer> to = new TestObserver<>();
Observable.range(1, 5).mergeWith(Completable.fromAction(new Action() {
@Override
public void run() throws Exception {
to.onNext(100);
}
})).subscribe(to);
to.assertResult(1, 2, 3, 4, 5, 100);
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class MaybeTest method observeOnCompleteThread.
@Test
public void observeOnCompleteThread() {
String main = Thread.currentThread().getName();
final String[] name = { null };
Maybe.empty().observeOn(Schedulers.single()).doOnComplete(new Action() {
@Override
public void run() throws Exception {
name[0] = Thread.currentThread().getName();
}
}).test().awaitDone(5, TimeUnit.SECONDS).assertResult();
assertNotEquals(main, name[0]);
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class FlowableConcatWithCompletableTest method normal.
@Test
public void normal() {
final TestSubscriber<Integer> ts = new TestSubscriber<>();
Flowable.range(1, 5).concatWith(Completable.fromAction(new Action() {
@Override
public void run() throws Exception {
ts.onNext(100);
}
})).subscribe(ts);
ts.assertResult(1, 2, 3, 4, 5, 100);
}
Aggregations