@Test(timeout = 1000) public void testSingleSourceManyIterators() { TestScheduler scheduler = new TestScheduler(); BlockingObservable<Long> source = Observable.interval(1, TimeUnit.SECONDS, scheduler).take(10).toBlockingObservable(); Iterable<Long> iter = source.mostRecent(-1L); for (int j = 0; j < 3; j++) { Iterator<Long> it = iter.iterator(); Assert.assertEquals(Long.valueOf(-1), it.next()); for (int i = 0; i < 9; i++) { scheduler.advanceTimeBy(1, TimeUnit.SECONDS); Assert.assertEquals(true, it.hasNext()); Assert.assertEquals(Long.valueOf(i), it.next()); } scheduler.advanceTimeBy(1, TimeUnit.SECONDS); Assert.assertEquals(false, it.hasNext()); } }
public static <T> Iterable<T> mostRecent(final Observable<? extends T> source, final T initialValue) { return new Iterable<T>() { @Override public Iterator<T> iterator() { MostRecentObserver<T> mostRecentObserver = new MostRecentObserver<T>(initialValue); final MostRecentIterator<T> nextIterator = new MostRecentIterator<T>(mostRecentObserver); source.subscribe(mostRecentObserver); return nextIterator; } }; }
OperationMostRecent { public static <T> Iterable<T> mostRecent(final Observable<? extends T> source, final T initialValue) { return new Iterable<T>() { @Override public Iterator<T> iterator() { MostRecentObserver<T> mostRecentObserver = new MostRecentObserver<T>(initialValue); final MostRecentIterator<T> nextIterator = new MostRecentIterator<T>(mostRecentObserver); source.subscribe(mostRecentObserver); return nextIterator; } }; } }
OperationMostRecent { public static <T> Iterable<T> mostRecent(final Observable<? extends T> source, final T initialValue) { return new Iterable<T>() { @Override public Iterator<T> iterator() { MostRecentObserver<T> mostRecentObserver = new MostRecentObserver<T>(initialValue); final MostRecentIterator<T> nextIterator = new MostRecentIterator<T>(mostRecentObserver); source.subscribe(mostRecentObserver); return nextIterator; } }; }  }
OperationMostRecent { public static <T> Iterable<T> mostRecent(final Observable<? extends T> source, final T initialValue) { return new Iterable<T>() { @Override public Iterator<T> iterator() { MostRecentObserver<T> mostRecentObserver = new MostRecentObserver<T>(initialValue); final MostRecentIterator<T> nextIterator = new MostRecentIterator<T>(mostRecentObserver); source.subscribe(mostRecentObserver); return nextIterator; } }; }  static Iterable<T> mostRecent(final Observable<? extends T> source, final T initialValue); }
OperationMostRecent { public static <T> Iterable<T> mostRecent(final Observable<? extends T> source, final T initialValue) { return new Iterable<T>() { @Override public Iterator<T> iterator() { MostRecentObserver<T> mostRecentObserver = new MostRecentObserver<T>(initialValue); final MostRecentIterator<T> nextIterator = new MostRecentIterator<T>(mostRecentObserver); source.subscribe(mostRecentObserver); return nextIterator; } }; }  static Iterable<T> mostRecent(final Observable<? extends T> source, final T initialValue);  }