Java Code Examples for io.reactivex.Scheduler#createWorker()
The following examples show how to use
io.reactivex.Scheduler#createWorker() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SchedulerHelper.java From rxjava2-extras with Apache License 2.0 | 6 votes |
public static void blockUntilWorkFinished(Scheduler scheduler, int numThreads, long timeout, TimeUnit unit) { final CountDownLatch latch = new CountDownLatch(numThreads); for (int i = 1; i <= numThreads; i++) { final Worker worker = scheduler.createWorker(); worker.schedule(new Runnable() { @Override public void run() { worker.dispose(); latch.countDown(); } }); } try { boolean finished = latch.await(timeout, unit); if (!finished) { throw new RuntimeException("timeout occured waiting for work to finish"); } } catch (InterruptedException e) { throw new RuntimeException(e); } }
Example 2
Source File: FlowableInsertTimeout.java From rxjava2-extras with Apache License 2.0 | 5 votes |
InsertTimeoutSubscriber(Subscriber<? super T> downstream, Function<? super T, ? extends Long> timeout, TimeUnit unit, Function<? super T, ? extends T> value, Scheduler scheduler) { this.downstream = downstream; this.timeout = timeout; this.unit = unit; this.value = value; this.queue = new MpscLinkedQueue<T>(); this.requested = new AtomicLong(); this.inserted = new AtomicLong(); this.terminated = new AtomicReference<Object>(); this.scheduled = new AtomicReference<Disposable>(); this.worker = scheduler.createWorker(); }
Example 3
Source File: SchedulerHelperTest.java From rxjava2-extras with Apache License 2.0 | 5 votes |
@Test public void testDispose() { Scheduler s = SchedulerHelper.withThreadId(Schedulers.trampoline(), "boo"); Worker w = s.createWorker(); Assert.assertFalse(w.isDisposed()); w.dispose(); Assert.assertTrue(w.isDisposed()); }