'Is it possible to delay the map method until the connection is complete? RxJava

new Retrofit.Builder().baseUrl("...").addCallAdapterFactory(RxJava3CallAdapterFactory.create()).build().create(RetrofitAPI.class).getCategories().map(responseBody -> {

    //I want to handle the JSON here in my way but the result is empty because the map method is called before the connection is completed.

    return responseBody;
}).subscribe(new SingleObserver<ResponseBody>() {
    @Override
    public void onSubscribe(@NonNull Disposable d) {
        Log.w("ABC", "onSubscribe");
    }

    @Override
    public void onSuccess(@NonNull ResponseBody responseBody) {
        Log.w("ABC", "onSuccess");
    }

    @Override
    public void onError(@NonNull Throwable e) {
        Log.w("ABC", "onError - " + e.getMessage());
    }
});

I'm getting the JSON from the server and I want to handle it in my way inside the map method but the JSON is always empty.



Solution 1:[1]

Retrofit, the default value for OkHttp is 10 seconds. Retrofit relies on the OkHttp default value.

you should read about retrofit timeout and assign your value for example (30 seconds)

&& that's will be helpful OkHttp/Retrofit default timeout

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mohmmaed-Amleh