api.getActiveSimpleOrder(rest_id) .subscribeOn(Schedulers.io()) **** .flatMap( result-> { if(result!=null) Observable::from;}) ****** .flatMap(offer -> api.getStatus(offer.getId()) // запрашиваем статус .doOnNext(offer::setStatus) // записываем полученный статус в объект заказа .map(status -> offer) // небольшая хитрость что бы дальше шли объекты заказов а не статусов ) .toList() // преобразуем последовательность обратно в список .observeOn(AndroidSchedulers.mainThread())// дальнейшие действия над данными будем производить в главном потоке .subscribe(offers::addAll, Exception -> Toast.makeText( getApplicationContext(), (CharSequence) Exception, Toast.LENGTH_LONG). show(), () -> { Toast.makeText( getApplicationContext(), "Data Receive Completed", Toast.LENGTH_SHORT). show(); sortOffers(offers); }); api.getActiveSimpleOrder (rest_id) returns a List which may be null Or not, if it is not empty then everything works. but if empty, then the string *** **** returns an expression that is not caught even by using try catch, maybe because of asynchrony,
The question is: how can the algorithm make it clear that if the observant arrives at null, then nothing needs to be done from what is written in the code?
filter( r -> r != null )doesn't suit you? - zRrr