retryUnary<R, Q> method
Future<R>
retryUnary<R, Q>(
- ResponseFuture<
R> rpc(- Q request, {
- CallOptions? options,
- Q request, {
- dynamic onRetry()?,
- CallOptions? options,
Call rpc
retrying so long as _shouldRefresh
return true
for the exception
thrown.
At every retry the onRetry
function will be called (if given). The
function rpc
will be invoked at-most this.attempts
times.
Implementation
Future<R> retryUnary<R, Q>(
$grpc.ResponseFuture<R> Function(Q request, {$grpc.CallOptions? options})
rpc,
Q request,
{Function(Exception)? onRetry,
$grpc.CallOptions? options}) async {
final client = http.Client();
return _retryOptions.retry(
() => rpc.call(request, options: options),
retryIf: (e) {
return e is $grpc.GrpcError &&
e.code == $grpc.StatusCode.unauthenticated;
},
onRetry: (e) async {
onRetry?.call(e);
await _refreshToken(_accessToken, null, client);
},
).whenComplete(() => client.close());
}