Answer the question
In order to leave comments, you need to log in
How to return an Object in a method when RxJava finishes running?
Good
There is a method, it should get an Object when Rxjava finishes, but I don’t know how to do it right, now I get a NullPointerException when calling.
Observable requests data from BD in io thread, Observer creates an instance of the class in the main thread - it all works. But how to wait for the method to wait for the completion of the request to the database, and not return null
here is an abridged excerpt
private DataTransferAddProduct addProduct;
@Override
public DataTransferAddProduct loadFromDB(int id_product) {
Observable.create(observableEmitter -> {
// тут происходит запрос
}).subscribeOn(Schedulers.io())
.observeOn(JavaFxScheduler.platform())
.subscribe(o -> {
addProduct = (DataTransferAddProduct) o;
});
/**return срабатывает до того, как вызовется - addProduct = (DataTransferAddProduct) o; */
return addProduct;
}
Answer the question
In order to leave comments, you need to log in
Well, you can call toBlocking(), but this is fundamentally wrong. Return further Observables, otherwise what for there in general rx?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question