use of io.reactivex.rxjava3.functions.Consumer in project RxJava by ReactiveX.
the class MaybeTest method usingNonEager.
@Test
public void usingNonEager() {
final AtomicInteger disposeCount = new AtomicInteger();
Maybe.using(Functions.justSupplier(1), new Function<Integer, MaybeSource<Integer>>() {
@Override
public MaybeSource<Integer> apply(Integer v) throws Exception {
return Maybe.just(v);
}
}, new Consumer<Integer>() {
@Override
public void accept(Integer d) throws Exception {
disposeCount.set(d);
}
}, false).map(new Function<Integer, Object>() {
@Override
public String apply(Integer v) throws Exception {
return "" + disposeCount.get() + v * 10;
}
}).test().assertResult("010");
assertEquals(1, disposeCount.get());
}
use of io.reactivex.rxjava3.functions.Consumer in project RxJava by ReactiveX.
the class ConnectableObservable method connect.
/**
* Instructs the {@code ConnectableObservable} to begin emitting the items from its underlying
* {@link Observable} to its {@link Observer}s.
* <p>
* To disconnect from a synchronous source, use the {@link #connect(Consumer)} method.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>The behavior is determined by the implementor of this abstract class.</dd>
* </dl>
*
* @return the {@link Disposable} representing the connection
* @see <a href="http://reactivex.io/documentation/operators/connect.html">ReactiveX documentation: Connect</a>
*/
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public final Disposable connect() {
ConnectConsumer cc = new ConnectConsumer();
connect(cc);
return cc.disposable;
}
use of io.reactivex.rxjava3.functions.Consumer in project RxJava by ReactiveX.
the class CompletableBlockingSubscribeTest method twoArgErrorFails.
@Test
public void twoArgErrorFails() throws Throwable {
TestHelper.withErrorTracking(errors -> {
Action action = mock(Action.class);
@SuppressWarnings("unchecked") Consumer<? super Throwable> consumer = mock(Consumer.class);
doThrow(new TestException()).when(consumer).accept(any());
Completable.error(new TestException()).delay(50, TimeUnit.MILLISECONDS, Schedulers.computation(), true).blockingSubscribe(action, consumer);
TestHelper.assertUndeliverable(errors, 0, TestException.class);
verify(action, never()).run();
verify(consumer).accept(any(TestException.class));
});
}
use of io.reactivex.rxjava3.functions.Consumer in project RxJava by ReactiveX.
the class CompletableBlockingSubscribeTest method twoArgErrorAsync.
@Test
public void twoArgErrorAsync() throws Throwable {
TestHelper.withErrorTracking(errors -> {
Action action = mock(Action.class);
@SuppressWarnings("unchecked") Consumer<? super Throwable> consumer = mock(Consumer.class);
Completable.error(new TestException()).delay(50, TimeUnit.MILLISECONDS, Schedulers.computation(), true).blockingSubscribe(action, consumer);
assertTrue("" + errors, errors.isEmpty());
verify(action, never()).run();
verify(consumer).accept(any(TestException.class));
});
}
use of io.reactivex.rxjava3.functions.Consumer in project RxJava by ReactiveX.
the class CompletableBlockingSubscribeTest method twoArgCompleteFails.
@Test
public void twoArgCompleteFails() throws Throwable {
TestHelper.withErrorTracking(errors -> {
Action action = mock(Action.class);
doThrow(new TestException()).when(action).run();
@SuppressWarnings("unchecked") Consumer<? super Throwable> consumer = mock(Consumer.class);
Completable.complete().blockingSubscribe(action, consumer);
TestHelper.assertUndeliverable(errors, 0, TestException.class);
verify(action).run();
verify(consumer, never()).accept(any());
});
}
Aggregations