Skip to content

How can I get my Observable to unsubscribe? #4415

@vgrazi

Description

@vgrazi

I am trying to understand how to unsubscribe from an Observable that is created from a live feed.
Here is more or less the code:

SomeFeed feed = new SomeFeed();
Observable<PriceTick> observable = Observable.create(s ->
  feed.register(new SomeListener() {
    @Override
    public void priceTick(PriceTick event) {
      s.onNext(event);
    }

    @Override
    public void error(Throwable throwable) {
      s.onError(throwable);
    }
  })
);
Subscription subscription = observable.subscribe(System.out::println);
subscription.unsubscribe();
System.out.println("Is unsubscribed:" + subscription.isUnsubscribed()); // prints true

I am finding that after the subscription is unsubscribed, the subscribed is still outputting the event stream.

How can I get the unsubscribe to remove the subscriber from the notifications?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions