@Test(timeout = 8000) public void testSingleSourceManyIterators() throws InterruptedException { BlockingObservable<Long> source = Observable.interval(200, TimeUnit.MILLISECONDS).take(10).toBlockingObservable(); Iterable<Long> iter = source.next(); for (int j = 0; j < 3; j++) { Iterator<Long> it = iter.iterator(); for (int i = 0; i < 9; i++) { Assert.assertEquals(true, it.hasNext()); Assert.assertEquals(Long.valueOf(i), it.next()); } Thread.sleep(400); Assert.assertEquals(false, it.hasNext()); } }
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);  }