@Test public void testNoBufferingOrBlockingOfSequence() throws Throwable { final CountDownLatch finished = new CountDownLatch(1); final int COUNT = 30; final CountDownLatch timeHasPassed = new CountDownLatch(COUNT); final AtomicBoolean running = new AtomicBoolean(true); final AtomicInteger count = new AtomicInteger(0); final Observable<Integer> obs = Observable.create(new Observable.OnSubscribeFunc<Integer>() { @Override public Subscription onSubscribe(final Observer<? super Integer> o) { new Thread(new Runnable() { @Override public void run() { try { while (running.get()) { o.onNext(count.incrementAndGet()); timeHasPassed.countDown(); } o.onCompleted(); } catch (Throwable e) { o.onError(e); } finally { finished.countDown(); } } }).start(); return Subscriptions.empty(); } }); Iterator<Integer> it = next(obs).iterator(); assertTrue(it.hasNext()); int a = it.next(); assertTrue(it.hasNext()); int b = it.next(); assertTrue("a and b should be different", a != b); timeHasPassed.await(8000, TimeUnit.MILLISECONDS); assertTrue(it.hasNext()); int c = it.next(); assertTrue("c should not just be the next in sequence", c != (b + 1)); assertTrue("expected that c [" + c + "] is higher than or equal to " + COUNT, c >= COUNT); assertTrue(it.hasNext()); int d = it.next(); assertTrue(d > c); running.set(false); finished.await(); assertFalse(it.hasNext()); System.out.println("a: " + a + " b: " + b + " c: " + c); }
public static <T> Iterable<T> next(final Observable<? extends T> items) { return new Iterable<T>() { @Override public Iterator<T> iterator() { NextObserver<T> nextObserver = new NextObserver<T>(); final NextIterator<T> nextIterator = new NextIterator<T>(nextObserver); items.materialize().subscribe(nextObserver); return nextIterator; } }; }
OperationNext { public static <T> Iterable<T> next(final Observable<? extends T> items) { return new Iterable<T>() { @Override public Iterator<T> iterator() { NextObserver<T> nextObserver = new NextObserver<T>(); final NextIterator<T> nextIterator = new NextIterator<T>(nextObserver); items.materialize().subscribe(nextObserver); return nextIterator; } }; } }
OperationNext { public static <T> Iterable<T> next(final Observable<? extends T> items) { return new Iterable<T>() { @Override public Iterator<T> iterator() { NextObserver<T> nextObserver = new NextObserver<T>(); final NextIterator<T> nextIterator = new NextIterator<T>(nextObserver); items.materialize().subscribe(nextObserver); return nextIterator; } }; }  }
OperationNext { public static <T> Iterable<T> next(final Observable<? extends T> items) { return new Iterable<T>() { @Override public Iterator<T> iterator() { NextObserver<T> nextObserver = new NextObserver<T>(); final NextIterator<T> nextIterator = new NextIterator<T>(nextObserver); items.materialize().subscribe(nextObserver); return nextIterator; } }; }  static Iterable<T> next(final Observable<? extends T> items); }
OperationNext { public static <T> Iterable<T> next(final Observable<? extends T> items) { return new Iterable<T>() { @Override public Iterator<T> iterator() { NextObserver<T> nextObserver = new NextObserver<T>(); final NextIterator<T> nextIterator = new NextIterator<T>(nextObserver); items.materialize().subscribe(nextObserver); return nextIterator; } }; }  static Iterable<T> next(final Observable<? extends T> items);  }