Skip to content

Unsubscribed observer receives event #3850

Closed
@alosich

Description

@alosich

This code:

import rx.Observable;
import rx.Subscription;
import rx.subjects.PublishSubject;

final class Unsubscribing {

   private static Subscription mFirst;
   private static Subscription mSecond;

   public static void main(final String[] args) {
      final PublishSubject<Integer> publisher = PublishSubject.create();

      mFirst = publisher.subscribe(i -> {
            mSecond.unsubscribe();
            log("first: " + i);
         } );

      mSecond = publisher.subscribe(i -> {
            log("second: " + i);
         } );


      publisher.onNext(1);
      publisher.onNext(2);
   }


   private static void log(final String msg) {
      System.out.println(msg);
   }

}

Unsubscribes second subscription in the first callback. At the time second callback called it is not subscribed (unsubscribe call completed for it).

It's expected that second callback will not be called, but it is.

Output of that program is

first: 1
second: 1
first: 2

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