Skip to content

Is there any way to get a Scheduler from OnSubscribe function? #941

@nsk-mironov

Description

@nsk-mironov

Hello.

My Observable is very simple and looks like:

Observable.create(new Observable.OnSubscribe<Content>() {
    @Override
    public void call(final Subscriber<? super Content> subscriber) {
        final ContentObserver observer = new ContentObserver() {
            @Override
            public void onContentChanged() {
                subscriber.onNext(loadContent());
            }
        };

        subscriber.add(Subscriptions.create(new Action0() {
            @Override
            public void call() {
                unregisterContentObserver(observer);
            }
        }));

        registerContentObserver(observer);
        subscriber.onNext(loadContent());
    }
});

loadContent is a heavy operation and have to be executed on the background thread (which is provided by the Scheduler that I pass to subscribeOn method).

PROBLEM
onContentChanged is always invoked from the UI thread and this cannot be changed, so I need to reschedule loadContent call to the background thread, but I failed to find a way to get a current Scheduler.

What is the right way to do it?

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