@Override public void onNext(Notification<? extends T> args) { if (waiting.getAndSet(false) || !args.isOnNext()) { Notification<? extends T> toOffer = args; while (!buf.offer(toOffer)) { Notification<? extends T> concurrentItem = buf.poll(); // in case if we won race condition with onComplete/onError method if (concurrentItem != null && !concurrentItem.isOnNext()) { toOffer = concurrentItem; } } } }
private boolean moveToNext() { try { Notification<? extends T> nextNotification = observer.takeNext(); if (nextNotification.isOnNext()) { isNextConsumed = false; next = nextNotification.getValue(); return true; } // If an observable is completed or fails, // hasNext() always return false. hasNext = false; if (nextNotification.isOnCompleted()) { return false; } if (nextNotification.isOnError()) { error = nextNotification.getThrowable(); throw Exceptions.propagate(error); } throw new IllegalStateException("Should not reach here"); } catch (InterruptedException e) { Thread.currentThread().interrupt(); error = e; throw Exceptions.propagate(error); } }
protected static <T> void emitValueToObserver(Notification<T> n, Observer<? super T> o) { n.accept(o); if (n.isOnNext()) { o.onCompleted(); } }