我正在使用Firebase云函数库在Android上进行开发,并使用getHttpsCallable
调用云函数。
问题是该函数需要10-15秒才能将结果返回给客户端,因此客户端会抛出异常java.net.SocketTimeoutException: timeout
。
代码
// Create the arguments to the callable function.
Map<String, Object> data = new HashMap<>();
data.put("info", info);
mFunctions.getHttpsCallable(function)
.call(data)
.continueWith(new Continuation<HttpsCallableResult, String>() {
@Override
public String then(@NonNull Task<HttpsCallableResult> task) {
// This continuation runs on either success or failure, but if the task
// has failed then getResult() will throw an Exception which will be
// propagated down.
if (task.isSuccessful()) {
String result = (String) task.getResult().getData();
Log.v(Constants.LOG_TAG, result);
return result;
} else {
// The condition never was true, always logs the exception.
Exception e = task.getException();
Log.e(Constants.LOG_TAG, "Failed to join multiplayer room.", e);
return null;
}
}
});
我该如何更改超时时间,以便客户端在抛出异常之前等待更长的时间?
注意:我不是使用OkHttp、Retrofit或默认的系统网络功能,而是使用Firebase Cloud Functions库(getHttpsCallable
)调用函数。