use of io.reactivex.rxjava3.core.Scheduler in project RxJava by ReactiveX.
the class RxJavaPluginsTest method overrideInitIoScheduler.
@Test
public void overrideInitIoScheduler() {
// make sure the Schedulers is initialized;
final Scheduler s = Schedulers.io();
Supplier<Scheduler> c = new Supplier<Scheduler>() {
@Override
public Scheduler get() throws Exception {
return s;
}
};
try {
RxJavaPlugins.setInitIoSchedulerHandler(initReplaceWithImmediate);
assertSame(ImmediateThinScheduler.INSTANCE, RxJavaPlugins.initIoScheduler(c));
} finally {
RxJavaPlugins.reset();
}
// make sure the reset worked
assertSame(s, RxJavaPlugins.initIoScheduler(c));
}
use of io.reactivex.rxjava3.core.Scheduler in project RxJava by ReactiveX.
the class AbstractSchedulerConcurrencyTests method unsubscribeRecursiveScheduleFromOutside.
@Test
public void unsubscribeRecursiveScheduleFromOutside() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
final CountDownLatch unsubscribeLatch = new CountDownLatch(1);
final AtomicInteger counter = new AtomicInteger();
final Worker inner = getScheduler().createWorker();
try {
inner.schedule(new Runnable() {
@Override
public void run() {
inner.schedule(new Runnable() {
int i;
@Override
public void run() {
System.out.println("Run: " + i++);
if (i == 10) {
latch.countDown();
try {
// wait for unsubscribe to finish so we are not racing it
unsubscribeLatch.await();
} catch (InterruptedException e) {
// we expect the countDown if unsubscribe is not working
// or to be interrupted if unsubscribe is successful since
// the unsubscribe will interrupt it as it is calling Future.cancel(true)
// so we will ignore the stacktrace
}
}
counter.incrementAndGet();
inner.schedule(this);
}
});
}
});
latch.await();
inner.dispose();
unsubscribeLatch.countDown();
// let time pass to see if the scheduler is still doing work
Thread.sleep(200);
assertEquals(10, counter.get());
} finally {
inner.dispose();
}
}
use of io.reactivex.rxjava3.core.Scheduler in project RxJava by ReactiveX.
the class FlowableBufferTimed method subscribeActual.
@Override
protected void subscribeActual(Subscriber<? super U> s) {
if (timespan == timeskip && maxSize == Integer.MAX_VALUE) {
source.subscribe(new BufferExactUnboundedSubscriber<>(new SerializedSubscriber<>(s), bufferSupplier, timespan, unit, scheduler));
return;
}
Scheduler.Worker w = scheduler.createWorker();
if (timespan == timeskip) {
source.subscribe(new BufferExactBoundedSubscriber<>(new SerializedSubscriber<>(s), bufferSupplier, timespan, unit, maxSize, restartTimerOnMaxSize, w));
return;
}
// Can't use maxSize because what to do if a buffer is full but its
// timespan hasn't been elapsed?
source.subscribe(new BufferSkipBoundedSubscriber<>(new SerializedSubscriber<>(s), bufferSupplier, timespan, timeskip, unit, w));
}
use of io.reactivex.rxjava3.core.Scheduler in project RxJava by ReactiveX.
the class ConnectableFlowable method connect.
/**
* Instructs the {@code ConnectableFlowable} to begin emitting the items from its underlying
* {@link Flowable} to its {@link Subscriber}s.
* <p>
* To disconnect from a synchronous source, use the {@link #connect(io.reactivex.rxjava3.functions.Consumer)} method.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>The behavior is determined by the implementor of this abstract class.</dd>
* </dl>
*
* @return the subscription 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.core.Scheduler in project RxJava by ReactiveX.
the class CallableAsyncPerf method setup.
@Setup
public void setup() {
Scheduler s = Schedulers.single();
Scheduler s2 = new SingleScheduler();
Callable<Integer> c = new Callable<Integer>() {
@Override
public Integer call() {
return 1;
}
};
subscribeOnFlowable = Flowable.fromCallable(c).subscribeOn(s);
observeOnFlowable = Flowable.fromCallable(c).observeOn(s);
pipelineFlowable = Flowable.fromCallable(c).subscribeOn(s).observeOn(s2);
// ----
subscribeOnObservable = Observable.fromCallable(c).subscribeOn(s);
observeOnObservable = Observable.fromCallable(c).observeOn(s);
pipelineObservable = Observable.fromCallable(c).subscribeOn(s).observeOn(s2);
// ----
observeOnSingle = Single.fromCallable(c).observeOn(s);
subscribeOnSingle = Single.fromCallable(c).subscribeOn(s);
pipelineSingle = Single.fromCallable(c).subscribeOn(s).observeOn(s2);
// ----
observeOnCompletable = Completable.fromCallable(c).observeOn(s);
subscribeOnCompletable = Completable.fromCallable(c).subscribeOn(s);
pipelineCompletable = Completable.fromCallable(c).subscribeOn(s).observeOn(s2);
// ----
observeOnMaybe = Maybe.fromCallable(c).observeOn(s);
subscribeOnMaybe = Maybe.fromCallable(c).subscribeOn(s);
pipelineMaybe = Maybe.fromCallable(c).subscribeOn(s).observeOn(s2);
}
Aggregations