Skip to content

Subscribing to a completed BehaviorSubject #462

Closed
@samuelgruetter

Description

@samuelgruetter

In C#, when I subscribe to an already completed BehaviorSubject, I only get an onComplete, as illustrated by this example:

static void Main() {
    var o = (new List<int> {1, 2, 3}).ToObservable();
    var subject = new BehaviorSubject<int>(0);
    o.Subscribe(subject);
    subject.Subscribe(
        i => Console.WriteLine(i),
        e => Console.WriteLine(e.Message),
        () => Console.WriteLine("complete")
    );
    Console.WriteLine("done");
    Console.ReadLine();
}

outputs:

complete
done

In the current Java implementation, I only get the last element and no onComplete:

Observable<Integer> o = Observable.from(1, 2, 3);
BehaviorSubject<Integer> subject = BehaviorSubject.createWithDefaultValue(0);
o.subscribe(subject);
subject.subscribe(
    new Action1<Integer>() { public void call(Integer i) {
        System.out.println(i);
    }},
    new Action1<Throwable>() { public void call(Throwable t) {
        t.printStackTrace();
    }},
    new Action0() { public void call() {
        System.out.println("complete");
    }}
);
System.out.println("done");

outputs:

3
done

And intuitively, I would expect that I get both the last element and onComplete.

So we have 3 options... Which one should RxJava choose?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions