use of io.reactivex.rxjava3.subscribers in project RxJava by ReactiveX.
the class ParallelRunOn method subscribe.
@Override
public void subscribe(Subscriber<? super T>[] subscribers) {
subscribers = RxJavaPlugins.onSubscribe(this, subscribers);
if (!validate(subscribers)) {
return;
}
int n = subscribers.length;
@SuppressWarnings("unchecked") final Subscriber<T>[] parents = new Subscriber[n];
if (scheduler instanceof SchedulerMultiWorkerSupport) {
SchedulerMultiWorkerSupport multiworker = (SchedulerMultiWorkerSupport) scheduler;
multiworker.createWorkers(n, new MultiWorkerCallback(subscribers, parents));
} else {
for (int i = 0; i < n; i++) {
createSubscriber(i, subscribers, parents, scheduler.createWorker());
}
}
source.subscribe(parents);
}
use of io.reactivex.rxjava3.subscribers in project RxRelay by JakeWharton.
the class PublishRelayTest method testReSubscribe.
/**
* Should be able to unsubscribe all Subscribers, have it stop emitting, then subscribe new ones and it start emitting again.
*/
@Test
public void testReSubscribe() {
final PublishRelay<Integer> ps = PublishRelay.create();
Observer<Integer> o1 = TestHelper.mockObserver();
TestObserver<Integer> ts = new TestObserver<Integer>(o1);
ps.subscribe(ts);
// emit
ps.accept(1);
// validate we got it
InOrder inOrder1 = inOrder(o1);
inOrder1.verify(o1, times(1)).onNext(1);
inOrder1.verifyNoMoreInteractions();
// unsubscribe
ts.dispose();
// emit again but nothing will be there to receive it
ps.accept(2);
Observer<Integer> o2 = TestHelper.mockObserver();
TestObserver<Integer> ts2 = new TestObserver<Integer>(o2);
ps.subscribe(ts2);
// emit
ps.accept(3);
// validate we got it
InOrder inOrder2 = inOrder(o2);
inOrder2.verify(o2, times(1)).onNext(3);
inOrder2.verifyNoMoreInteractions();
ts2.dispose();
}
use of io.reactivex.rxjava3.subscribers in project RxJava by ReactiveX.
the class FlowableTakeUntilTest method untilPublisherMainError.
@Test
public void untilPublisherMainError() {
PublishProcessor<Integer> main = PublishProcessor.create();
PublishProcessor<Integer> other = PublishProcessor.create();
TestSubscriber<Integer> ts = main.takeUntil(other).test();
assertTrue("Main no subscribers?", main.hasSubscribers());
assertTrue("Other no subscribers?", other.hasSubscribers());
main.onError(new TestException());
assertFalse("Main has subscribers?", main.hasSubscribers());
assertFalse("Other has subscribers?", other.hasSubscribers());
ts.assertFailure(TestException.class);
}
use of io.reactivex.rxjava3.subscribers in project RxJava by ReactiveX.
the class ParallelRunOnTest method missingBackpressure.
@Test
public void missingBackpressure() {
new ParallelFlowable<Integer>() {
@Override
public int parallelism() {
return 1;
}
@Override
public void subscribe(Subscriber<? super Integer>[] subscribers) {
subscribers[0].onSubscribe(new BooleanSubscription());
subscribers[0].onNext(1);
subscribers[0].onNext(2);
subscribers[0].onNext(3);
}
}.runOn(ImmediateThinScheduler.INSTANCE, 1).sequential(1).test(0).assertFailure(MissingBackpressureException.class);
}
use of io.reactivex.rxjava3.subscribers in project RxJava by ReactiveX.
the class ParallelInvalid method subscribe.
@Override
public void subscribe(Subscriber<? super Object>[] subscribers) {
TestException ex = new TestException();
for (Subscriber<? super Object> s : subscribers) {
EmptySubscription.error(ex, s);
s.onError(ex);
s.onNext(0);
s.onComplete();
s.onComplete();
}
}
Aggregations