コード例 #1
0
  @Override
  public void onNext(T t) {
    synchronized (this) {
      if (emitting) {
        List<T> q = queue;
        if (q == null) {
          q = new ArrayList<T>(4);
          queue = q;
        }
        q.add(t);
        return;
      }
    }
    boolean skipFinal = false;
    try {
      child.onNext(t);

      long r = requested;
      if (r != Long.MAX_VALUE) {
        requested = r - 1;
      }

      emitLoop();
      skipFinal = true;
    } finally {
      if (!skipFinal) {
        synchronized (this) {
          emitting = false;
        }
      }
    }
  }
コード例 #2
0
    void subscribeNext() {
      Observable<? extends T> t;
      synchronized (guard) {
        t = queue.peek();
        if (t == null || active >= maxConcurrency) {
          return;
        }
        active++;
        queue.poll();
      }

      MergeItemSubscriber itemSub = new MergeItemSubscriber(SOURCE_INDEX.getAndIncrement(this));
      subscribers.add(itemSub);

      csub.add(itemSub);

      WIP.incrementAndGet(this);

      t.unsafeSubscribe(itemSub);

      request(1);
    }