D
D
Denis2018-02-02 08:59:34
Java
Denis, 2018-02-02 08:59:34

How to execute intents asynchronously in RxJava?

This is my first time using rxjava and after reading about
subscribeOn(Schedulers.newThread())
observeOn(Schedulers.newThread())
I was hoping I could do something like this:

Subject<DataObservable> commandToService.subscribeOn(Schedulers.newThread()).observeOn(Schedulers.newThread()).subscribe(observer);
//слушатель
private Observer<DataObservable> observer = new Observer<DataObservable>() {
        @Override
        public void onNext(DataObservable o) {
              //какая-то долгая операция
        }
    };

private void postCommand(DataObservable command){
        commandToService.onNext(command);
}

I wanted postCommand to be called from different parts of the program, and the observer to perform various long operations. But it turned out that the intentions created by postCommand are executed synchronously, that is, until one intention is completed, a new one does not start, contrary to my expectation.
Tell me, is it possible to make rxjava run intentions in parallel, or will I have to create new threads in observer.onNext myself?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question