Skip to content

Subscribing to a completed BehaviorSubject #462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
samuelgruetter opened this issue Nov 2, 2013 · 2 comments
Closed

Subscribing to a completed BehaviorSubject #462

samuelgruetter opened this issue Nov 2, 2013 · 2 comments

Comments

@samuelgruetter
Copy link
Contributor

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?

@samuelgruetter
Copy link
Contributor Author

I'm asking this because maybe we can use BehaviorSubject to implement the delay operator.

@benjchristensen
Copy link
Member

Fixed in 564fba0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants