Skip to content
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

Split SubscribeOn into SubscribeOn/UnsubscribeOn #890

Merged

Conversation

benjchristensen
Copy link
Member

Working with @headinthebox based on discussions at #869 and #880 (comment) we determined that there are times when unsubscribeOn behavior is needed.

The subscribeOn operator can not mix subscribe and unsubscribe scheduling behavior without breaking the lift/Subscriber behavior that allows unsubscribing synchronous sources. The newly added unsubscribeOn operator will not work with synchronous unsubscribes, but it will work for the targeted use cases such as UI event handlers.

Working with @headinthebox based on discussions at ReactiveX#869 and ReactiveX#880 (comment) we determined that there are times when `unsubscribeOn` behavior is needed.

The `subscribeOn` operator can not mix `subscribe` and `unsubscribe` scheduling behavior without breaking the `lift`/`Subscriber` behavior that allows unsubscribing synchronous sources. The newly added `unsubscribeOn` operator will not work with synchronous unsubscribes, but it will work for the targeted use cases such as UI event handlers.
benjchristensen added a commit that referenced this pull request Feb 17, 2014
Split SubscribeOn into SubscribeOn/UnsubscribeOn
@benjchristensen benjchristensen merged commit ad6c70b into ReactiveX:master Feb 17, 2014
@benjchristensen benjchristensen deleted the subscribeOn-subscriptions branch February 17, 2014 20:33
@zsxwing
Copy link
Member

zsxwing commented Feb 18, 2014

I think this still can not guarantee that unsubscribe is always called in the scheduler. For example,

    public static void main(String[] args) throws InterruptedException {
        Observable.create(new OnSubscribe<Integer>() {

            @Override
            public void call(final Subscriber<? super Integer> t1) {
                final Subscription s = Subscriptions.create(new Action0() {

                    @Override
                    public void call() {
                        System.out.println(Thread.currentThread().getName());
                    }
                });
                t1.add(s);
                t1.onNext(1);
                t1.onNext(2);
                t1.onCompleted();
            }
        }).take(1).observeOn(Schedulers.io()).unsubscribeOn(Schedulers.newThread()).subscribe();
    }

will output main in my PC.

@zsxwing
Copy link
Member

zsxwing commented Feb 18, 2014

As you said, it can not work for synchronous unsubscribes, so we still need to write a thread-safe Subscription. I just feel unsubscribeOn will confuse users that when to use unsubscribeOn and when it's necessary to write a thread-safe Subscription.

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

Successfully merging this pull request may close these issues.

None yet

2 participants