runWithClient<R extends HasBillingResponse> method
Executes the given action
with access to the underlying BillingClient.
If necessary, waits for the underlying BillingClient to connect.
If given action
returns BillingResponse.serviceDisconnected, it will
be transparently retried after the connection is restored. Because
of this, action
may be called multiple times.
A response with BillingResponse.serviceDisconnected may be returned in case of dispose being called during the operation.
See runWithClientNonRetryable for operations that do not return a subclass of HasBillingResponse.
Implementation
Future<R> runWithClient<R extends HasBillingResponse>(
Future<R> Function(BillingClient client) action,
) async {
_debugAssertNotDisposed();
await _readyFuture;
final R result = await action(client);
if (result.responseCode == BillingResponse.serviceDisconnected &&
!_isDisposed) {
await _connect();
return runWithClient(action);
} else {
return result;
}
}