void complete(int id) { List<Object> localQueue; synchronized (guard) { if (id != index) { return; } active = false; if (!mainDone) { return; } if (emitting) { if (queue == null) { queue = new ArrayList<Object>(); } queue.add(nl.completed()); return; } localQueue = queue; queue = null; emitting = true; } drain(localQueue); serializedChild.onCompleted(); unsubscribe(); }
void drain(List<Object> localQueue) { if (localQueue == null) { return; } for (Object o : localQueue) { if (nl.isCompleted(o)) { serializedChild.onCompleted(); break; } else if (nl.isError(o)) { serializedChild.onError(nl.getError(o)); break; } else { @SuppressWarnings("unchecked") T t = (T) o; serializedChild.onNext(t); arbiter.produced(1); } } }
@Override public void onCompleted() { List<Object> localQueue; synchronized (guard) { mainDone = true; if (active) { return; } if (emitting) { if (queue == null) { queue = new ArrayList<Object>(); } queue.add(nl.completed()); return; } localQueue = queue; queue = null; emitting = true; } drain(localQueue); serializedChild.onCompleted(); unsubscribe(); }