timedSync<T> static method
Log execution time of a synchronous function
Implementation
static T timedSync<T>(
T Function() function, {
String? label,
String tag = 'Reactiv',
}) {
final stopwatch = Stopwatch()..start();
final functionLabel = label ?? 'Function';
_log(LogLevel.debug, '⏱️ $functionLabel started...', tag: tag);
try {
final result = 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;
}
}