/** * Shuts down the standard Schedulers. * <p>The operation is idempotent and thread-safe. */ public static void shutdown() { computation().shutdown(); io().shutdown(); newThread().shutdown(); single().shutdown(); trampoline().shutdown(); SchedulerPoolFactory.shutdown(); }
@Override protected Scheduler getScheduler() { return Schedulers.from(executor); }
@Override public Publisher<Integer> apply(Integer i) { return incrementingIntegers(new AtomicInteger()) .take(10) .subscribeOn(Schedulers.computation()); } }
@Override protected Scheduler getScheduler() { return Schedulers.trampoline(); }
@Test public void overrideIoScheduler() { try { RxJavaCommonPlugins.setIoSchedulerHandler(replaceWithImmediate); assertSame(ImmediateThinScheduler.INSTANCE, Schedulers.io()); } finally { RxJavaCommonPlugins.reset(); } // make sure the reset worked assertNotSame(ImmediateThinScheduler.INSTANCE, Schedulers.io()); }
@Override protected Scheduler getScheduler() { return Schedulers.newThread(); }
@Override public SingleSource<Object> apply(Single<Object> v) throws Exception { return v.unsubscribeOn(Schedulers.single()); } });
@Test public void doubleObserveOn() { Flowable.just(1).hide() .observeOn(Schedulers.computation()) .observeOn(Schedulers.single()) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(1); }
@Override public SingleSource<Integer> apply(Integer v) throws Exception { return Single.just(v).subscribeOn(Schedulers.computation()); } })
@Override public void run() { String msg = key + ".1"; workDone.add(msg); System.out.println(msg); Worker worker3 = Schedulers.trampoline().createWorker(); worker3.schedule(createPrintAction(key + ".B.1", workDone)); worker3.schedule(createPrintAction(key + ".B.2", workDone)); }
@Override public ObservableSource<Integer> apply(Integer i) throws Exception { return i == 3 ? Observable.just(i) : Observable .just(i) .delay(1, TimeUnit.MILLISECONDS, Schedulers.io()); } })
@Override public Observable<String> apply(final GroupedObservable<Integer, Integer> group) { return group.subscribeOn(Schedulers.newThread()).map(new Function<Integer, String>() { @Override public String apply(Integer t1) { System.out.println("Received: " + t1 + " on group : " + group.getKey()); return "first groups: " + t1; } }); }
/** * Synchronizes the execution of two runnables (as much as possible) * to test race conditions. * <p>The method blocks until both have run to completion. * @param r1 the first runnable * @param r2 the second runnable */ public static void race(final Runnable r1, final Runnable r2) { race(r1, r2, Schedulers.single()); } /**
/** * Starts the standard Schedulers. * <p>The operation is idempotent and thread-safe. */ public static void start() { computation().start(); io().start(); newThread().start(); single().start(); trampoline().start(); SchedulerPoolFactory.start(); }
@Override public Flowable<Integer> apply(Integer t) { return Flowable.range(1, 1000).subscribeOn(Schedulers.computation()); } }).observeOn(Schedulers.single())
@Override public void run() { String msg = key + ".1"; workDone.add(msg); System.out.println(msg); Worker worker3 = Schedulers.trampoline().createWorker(); worker3.schedule(createPrintAction(key + ".B.1", workDone)); worker3.schedule(createPrintAction(key + ".B.2", workDone)); }
@Test public void timeoutException() throws Exception { Completable.never() .timeout(100, TimeUnit.MILLISECONDS, Schedulers.io()) .test() .awaitDone(5, TimeUnit.SECONDS) .assertFailure(TimeoutException.class); }
@Override public Flowable<String> apply(final GroupedFlowable<Integer, Integer> group) { return group.subscribeOn(Schedulers.newThread()).map(new Function<Integer, String>() { @Override public String apply(Integer t1) { System.out.println("Received: " + t1 + " on group : " + group.getKey()); return "first groups: " + t1; } }); }
/** * Synchronizes the execution of two runnables (as much as possible) * to test race conditions. * <p>The method blocks until both have run to completion. * @param r1 the first runnable * @param r2 the second runnable */ public static void race(final Runnable r1, final Runnable r2) { race(r1, r2, Schedulers.single()); } /**
@Test(timeout = 1000) public void runnableDisposedAsync2() throws Exception { final Scheduler s = Schedulers.from(executor); Disposable d = s.scheduleDirect(Functions.EMPTY_RUNNABLE); while (!d.isDisposed()) { Thread.sleep(1); } }