/** * Makes sure the fast-path emits in order. * @param value the value to emit or queue up * @param delayError if true, errors are delayed until the source has terminated * @param disposable the resource to dispose if the drain terminates */ protected final void fastPathOrderedEmit(U value, boolean delayError, Disposable disposable) { final Observer<? super V> observer = downstream; final SimplePlainQueue<U> q = queue; if (wip.get() == 0 && wip.compareAndSet(0, 1)) { if (q.isEmpty()) { accept(observer, value); if (leave(-1) == 0) { return; } } else { q.offer(value); } } else { q.offer(value); if (!enter()) { return; } } QueueDrainHelper.drainLoop(q, observer, delayError, disposable, this); }
@Nullable @Override public T poll() throws Exception { return queue.poll(); }
@Override public void clear() { queue.clear(); }
@Override public void onNext(T t) { queue.offer(t); drain(); }
@Override public boolean isEmpty() { return queue.isEmpty(); } }
@Override public void onNext(T t) { queue.offer(t); drain(); }
public static <T, U> void drainLoop(SimplePlainQueue<T> q, Observer<? super U> a, boolean delayError, Disposable dispose, ObservableQueueDrain<T, U> qd) { int missed = 1; for (;;) { if (checkTerminated(qd.done(), q.isEmpty(), a, delayError, q, dispose, qd)) { return; } for (;;) { boolean d = qd.done(); T v = q.poll(); boolean empty = v == null; if (checkTerminated(d, empty, a, delayError, q, dispose, qd)) { return; } if (empty) { break; } qd.accept(a, v); } missed = qd.leave(-missed); if (missed == 0) { break; } } }
@Override public boolean isEmpty() { return queue.isEmpty(); } }
ScanSeedSubscriber(Subscriber<? super R> actual, BiFunction<R, ? super T, R> accumulator, R value, int prefetch) { this.downstream = actual; this.accumulator = accumulator; this.value = value; this.prefetch = prefetch; this.limit = prefetch - (prefetch >> 2); this.queue = new SpscArrayQueue<R>(prefetch); this.queue.offer(value); this.requested = new AtomicLong(); }
public static <T, U> void drainLoop(SimplePlainQueue<T> q, Observer<? super U> a, boolean delayError, Disposable dispose, ObservableQueueDrain<T, U> qd) { int missed = 1; for (;;) { if (checkTerminated(qd.done(), q.isEmpty(), a, delayError, q, dispose, qd)) { return; } for (;;) { boolean d = qd.done(); T v = q.poll(); boolean empty = v == null; if (checkTerminated(d, empty, a, delayError, q, dispose, qd)) { return; } if (empty) { break; } qd.accept(a, v); } missed = qd.leave(-missed); if (missed == 0) { break; } } }
@Override public void clear() { queue.clear(); }
@Nullable @Override public T poll() throws Exception { return queue.poll(); }
@Override public void onComplete() { List<U> bs; synchronized (this) { bs = new ArrayList<U>(buffers); buffers.clear(); } for (U b : bs) { queue.offer(b); } done = true; if (enter()) { QueueDrainHelper.drainMaxLoop(queue, downstream, false, w, this); } }