I have to implement a function that call a service until the status of the returned body is depositDone or faulted. If the status is not one of those, i have to call again the service, with a delay of 500 milliseconds from the last one.
It's the first time i'm using RxJava and i don't know if I am doing it correctly, since i can not test it at the moment.
private void startPollingPaymentStatus() {
        Observable<CimaPaymentStatusResponse> response = request.getPaymentStatus();
        response.subscribeOn(Schedulers.io())
                .map(result -> result.paymentStatus)
                .takeUntil(responseState -> (responseState == CimaPaymentEnum.depositDone || responseState == CimaPaymentEnum.faulted))
                .debounce(500, TimeUnit.MILLISECONDS)
                .subscribe(this::onPaymentPollingUpdate, this::handleCimaError);
    }
    private void onPaymentPollingUpdate(CimaPaymentEnum cimaPaymentEnum) {
        if (cimaPaymentEnum == CimaPaymentEnum.depositDone || cimaPaymentEnum == CimaPaymentEnum.faulted) {
            //stop polling, operation completed
            onCustomPaymentDone(null, cimaPayment, null);
        } else {
            // Not successful
            CustomAlertDialog customAlertDialog = new CustomAlertDialog(this);
            customAlertDialog.setTitle(R.string.payments_cima);
            customAlertDialog.setMessage(R.string.cima_payment_error);
            customAlertDialog.setPositiveButton(getString(R.string.ok), null);
            customAlertDialog.show();
        }
    } 
Am I doing right?
