@Override protected void onNext(Context context, Subscriber<? super T> subscriber, T data) { AtomicLong count = subs.get(subscriber); if (count == null) return; // Means we already completed it long remaining = count.decrementAndGet(); super.onNext(context, subscriber, data); if (remaining == 0) { close(); } }
@Override public void subscribe(Subscriber<? super T> subscriber) { subs.put(subscriber, new AtomicLong(elements)); super.subscribe(subscriber); }