Fetch
Fetch copied to clipboard
Custom Time Out
Context
on my server it takes 20 seconds to generate a document, after generating it is returned, taking into account this scenario I need to increase the library's default timeout, in my code it works, but the file cannot be opened.
Code:
private static final Long TIME_OUT = 30_000L;
public RNBackgroundDownloaderModule(ReactApplicationContext reactContext) {
super(reactContext);
loadConfigMap();
FetchConfiguration fetchConfiguration = new FetchConfiguration.Builder(this.getReactApplicationContext())
.setDownloadConcurrentLimit(4)
.setHttpDownloader(getOkHttpDownloader())
.setNamespace("RNBackgroundDownloader")
.build();
fetch = Fetch.Impl.getInstance(fetchConfiguration);
fetch.addListener(this);
}
private OkHttpDownloader getOkHttpDownloader() {
final OkHttpClient okHttpClient = new OkHttpClient.Builder()
.readTimeout(TIME_OUT, TimeUnit.MILLISECONDS)
.connectTimeout(3000, TimeUnit.MILLISECONDS)
.writeTimeout(3000,TimeUnit.MILLISECONDS)
.build();
return new OkHttpDownloader(okHttpClient,
Downloader.FileDownloaderType.PARALLEL);
}
}