withClient<R> method
Null safety
- Future<
R> fn(- TrackingClient client
- {bool invalidateOnError = false,
- bool forceCloseOnError = false}
Runs a function with a TrackingClient as parameter and handles invalidation on exceptions.
The client remains the same until the function completes.
Implementation
Future<R> withClient<R>(
Future<R> Function(TrackingClient client) fn, {
bool invalidateOnError = false,
bool forceCloseOnError = false,
}) async {
_initCleanupTimer();
final client = await _allocate();
try {
return await fn(client._client);
} catch (_) {
if (_invalidateOnError ||
invalidateOnError ||
_forceCloseOnError ||
forceCloseOnError) {
client._forceClose = _forceCloseOnError || forceCloseOnError;
if (_current == client) {
_current = null;
_pastClients.add(client);
}
}
rethrow;
} finally {
await _release(client);
}
}