timed<T> static method
Log execution time of a function
Implementation
static Future<T> timed<T>(
Future<T> Function() function, {
String? label,
String tag = 'Reactiv',
}) async {
final stopwatch = Stopwatch()..start();
final functionLabel = label ?? 'Function';
_log(LogLevel.debug, '⏱️ $functionLabel started...', tag: tag);
try {
final result = await function();
stopwatch.stop();
_log(
LogLevel.debug,
'✅ $functionLabel completed in ${stopwatch.elapsedMilliseconds}ms',
tag: tag,
);
return result;
} catch (e, stack) {
stopwatch.stop();
_log(
LogLevel.error,
'❌ $functionLabel failed after ${stopwatch.elapsedMilliseconds}ms',
tag: tag,
error: e,
stackTrace: stack,
);
rethrow;
}
}