@Override public void request(long n) { if (SubscriptionHelper.validateRequest(n)) { return; } if (compareAndSet(false, true)) { int i = 0; final Subscriber<? super Integer> a = s; final AtomicInteger c = counter; while (!cancelled) { a.onNext(i++); c.incrementAndGet(); } System.out.println("unsubscribed after: " + i); } }
@Override public void subscribe(Subscriber<? super String> observer) { observer.onSubscribe(EmptySubscription.INSTANCE); boolean errorThrown = false; for (String s : valuesToReturn) { if (s == null) { System.out.println("throwing exception"); observer.onError(new NullPointerException()); errorThrown = true; // purposefully not returning here so it will continue calling onNext // so that we also test that we handle bad sequences like this } else { observer.onNext(s); } } if (!errorThrown) { observer.onComplete(); } }
@Override public void subscribe(Subscriber<? super String> observer) { observer.onSubscribe(EmptySubscription.INSTANCE); observer.onNext("hello"); observer.onComplete(); }