import 'dart:async'; /// Release every owned resource, then report the first cleanup failure. Future completeCleanup(List Function()> actions) async { Object? failure; StackTrace? trace; for (final action in actions) { try { await action(); } catch (error, stack) { failure ??= error; trace ??= stack; } } if (failure != null) Error.throwWithStackTrace(failure, trace!); }