void fastPath() { final Iterator<? extends T> a = iterator; final Subscriber<? super T> s = actual; for (; ; ) { if (cancelled) { return; } T t; try { t = a.next(); } catch (Exception ex) { s.onError(ex); return; } if (cancelled) { return; } if (t == null) { s.onError(new NullPointerException("The iterator returned a null value")); return; } s.onNext(t); if (cancelled) { return; } boolean b; try { b = a.hasNext(); } catch (Exception ex) { s.onError(ex); return; } if (cancelled) { return; } if (!b) { s.onComplete(); return; } } }
/** * Common method to take an Iterator as a source of values. * * @param s * @param it */ static <T> void subscribe(Subscriber<? super T> s, Iterator<? extends T> it) { if (it == null) { EmptySubscription.error(s, new NullPointerException("The iterator is null")); return; } boolean b; try { b = it.hasNext(); } catch (Throwable e) { EmptySubscription.error(s, e); return; } if (!b) { EmptySubscription.complete(s); return; } s.onSubscribe(new PublisherIterableSubscription<>(s, it)); }
@Override public boolean isTerminated() { return !iterator.hasNext(); }
@Override public boolean isStarted() { return iterator.hasNext(); }
void slowPath(long n) { final Iterator<? extends T> a = iterator; final Subscriber<? super T> s = actual; long e = 0L; for (; ; ) { while (e != n) { T t; try { t = a.next(); } catch (Throwable ex) { s.onError(ex); return; } if (cancelled) { return; } if (t == null) { s.onError(new NullPointerException("The iterator returned a null value")); return; } s.onNext(t); if (cancelled) { return; } boolean b; try { b = a.hasNext(); } catch (Throwable ex) { s.onError(ex); return; } if (cancelled) { return; } if (!b) { s.onComplete(); return; } e++; } n = requested; if (n == e) { n = REQUESTED.addAndGet(this, -e); if (n == 0L) { return; } e = 0L; } } }