Beispiel #1
0
    @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;
          }
        }
      }
    }
Beispiel #2
0
 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);
   }
 }
Beispiel #3
0
 protected static <T> void emitValueToObserver(Notification<T> n, Observer<? super T> o) {
   n.accept(o);
   if (n.isOnNext()) {
     o.onCompleted();
   }
 }