Answer the question
In order to leave comments, you need to log in
How to implement a request queue with Rx?
My application has an asynchronous makeRequest() method with a callback. This method is called many times from different classes. It is necessary that the execution of the contents of this method occurs sequentially (while the first request is being executed, the rest are waiting).
It would be desirable to implement it by means of Rx. In my opinion, it should look something like this:
public void execute() { // Этот метод вызывается многократно из разных классов
Observable.just(true)
// Что здесь нужно добавить для ожидания?
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.map(o -> {
internalExecute();
return o;
})
.subscribe();
}
private void internalExecute() { // Этот метод должен запускаться, только когда предыдущий запуск финишировал
makeRequest(this::onRequestFinished);
}
private void onRequestFinished() {
// Здесь обрабатывается завершений запроса
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question