0

I am following book which uses subscriber.isUnsubscribed() but it is no longer available in version 2.0. Can somebody guide me how to rewrite this code to be able to use isUnsubscribed check in the Observable lambda?

Observable<BigInteger> naturalNumbers = Observable.create(
    subscriber -> {
        Runnable r = () -> {
            BigInteger i = ZERO;
            while (!subscriber.isUnsubscribed()) {
                subscriber.onNext(i);
                i = i.add(ONE);
            }
        };
        new Thread(r).start();
    });


Subscription subscription = naturalNumbers.subscribe(x -> log(x));
//after some time...
subscription.unsubscribe();
mike
  • 1,670
  • 11
  • 21

0 Answers0