runWithInvariantAsync<R> method
Runs body and evaluates invariant afterward, even if body throws.
Returns the result of body when both the operation and invariant check
succeed. If body throws and the invariant check succeeds, the body's
exception propagates. If the invariant check also fails, the invariant
failure takes precedence.
Implementation
@nonVirtual
Future<R> runWithInvariantAsync<R>(
String description,
Future<R> Function() body,
) async {
try {
final result = await body();
return result;
} finally {
_evaluateInvariant(description);
}
}