@Test public void hasNextWithTimeout() throws Exception { BlockingIterator<Integer> iterator = source.toIterable().iterator(); assertTrue(source.isSubscribed()); TestSubscription subscription = new TestSubscription(); source.onSubscribe(subscription); source.onNext(1, 2); assertThat("hasNext timed out.", iterator.hasNext(-1, MILLISECONDS), is(true)); assertThat("Unexpected item found.", iterator.next(-1, MILLISECONDS), is(1)); assertThat("Unexpected item found.", iterator.next(-1, MILLISECONDS), is(2)); expected.expect(instanceOf(TimeoutException.class)); try { iterator.hasNext(10, MILLISECONDS); fail("expected exception"); } catch (TimeoutException e) { assertThat("Unexpected item found.", iterator.hasNext(-1, MILLISECONDS), is(false)); assertTrue(subscription.isCancelled()); throw e; } }
@Override public BlockingIterator<T> iterator() { SubscriberAndIterator<T> subscriberAndIterator = new SubscriberAndIterator<>(queueCapacityHint); original.subscribeInternal(subscriberAndIterator); return subscriberAndIterator; }
PublisherAsBlockingIterable implements BlockingIterable<T> { @Override public BlockingIterator<T> iterator() { SubscriberAndIterator<T> subscriberAndIterator = new SubscriberAndIterator<>(queueCapacityHint); original.subscribeInternal(subscriberAndIterator); return subscriberAndIterator; } }
PublisherAsBlockingIterable implements BlockingIterable<T> { @Override public BlockingIterator<T> iterator() { SubscriberAndIterator<T> subscriberAndIterator = new SubscriberAndIterator<>(queueCapacityHint); original.subscribeInternal(subscriberAndIterator); return subscriberAndIterator; } PublisherAsBlockingIterable(final Publisher<T> original);   PublisherAsBlockingIterable(final Publisher<T> original, int queueCapacityHint); }
PublisherAsBlockingIterable implements BlockingIterable<T> { @Override public BlockingIterator<T> iterator() { SubscriberAndIterator<T> subscriberAndIterator = new SubscriberAndIterator<>(queueCapacityHint); original.subscribeInternal(subscriberAndIterator); return subscriberAndIterator; } PublisherAsBlockingIterable(final Publisher<T> original);   PublisherAsBlockingIterable(final Publisher<T> original, int queueCapacityHint); @Override BlockingIterator<T> iterator(); }
PublisherAsBlockingIterable implements BlockingIterable<T> { @Override public BlockingIterator<T> iterator() { SubscriberAndIterator<T> subscriberAndIterator = new SubscriberAndIterator<>(queueCapacityHint); original.subscribeInternal(subscriberAndIterator); return subscriberAndIterator; } PublisherAsBlockingIterable(final Publisher<T> original);   PublisherAsBlockingIterable(final Publisher<T> original, int queueCapacityHint); @Override BlockingIterator<T> iterator();  }