예제 #1
0
    @Override
    public void next(Object value) {
      if (value == null) {
        fail(new NullPointerException("value is null"));
        return;
      }
      if (done) {
        Exceptions.onNextDropped(value);
        return;
      }
      if (caughtUp && actual != null) {
        try {
          actual.onNext(value);
        } finally {
          ch.read();
          ReferenceCountUtil.release(value);
        }

      } else {
        Queue<Object> q = queue;
        if (q == null) {
          q = QueueSupplier.unbounded().get();
          queue = q;
        }
        q.offer(value);
        if (drain()) {
          caughtUp = true;
        }
      }
    }
  @Test
  public void subsequentSumAsync() {

    AssertSubscriber<Integer> ts = AssertSubscriber.create();

    UnicastProcessor<Integer> up = UnicastProcessor.create(QueueSupplier.<Integer>get(16).get());

    up.publish(o -> zip((Object[] a) -> (Integer) a[0] + (Integer) a[1], o, o.skip(1)))
        .subscribe(ts);

    up.onNext(1);
    up.onNext(2);
    up.onNext(3);
    up.onNext(4);
    up.onNext(5);
    up.onComplete();

    ts.assertValues(1 + 2, 2 + 3, 3 + 4, 4 + 5).assertNoError().assertComplete();
  }