bootFinished function
Called after Nylo finishes setup.
nylo - The Nylo instance.
providers - Map of provider types to provider instances.
key - The key to save the Nylo instance in the Backpack.
enableDebugLogging - When true, logs boot timing for each provider.
Defaults to the value of APP_DEBUG environment variable.
throwOnError - When true, rethrows errors instead of silently catching them.
Defaults to false for backwards compatibility.
Implementation
Future<Nylo> bootFinished(
Nylo nylo,
Map<Type, NyProvider> providers, {
String key = "nylo",
bool? enableDebugLogging,
bool throwOnError = false,
}) async {
final bool shouldLog =
enableDebugLogging ?? getEnv('APP_DEBUG', defaultValue: false);
for (final entry in providers.entries) {
final providerName = entry.key.toString();
final provider = entry.value;
final Stopwatch? stopwatch = shouldLog ? (Stopwatch()..start()) : null;
try {
await provider.boot(nylo);
if (shouldLog && stopwatch != null) {
stopwatch.stop();
NyLogger.debug(
'[$providerName] boot completed in ${stopwatch.elapsedMilliseconds}ms',
);
}
} catch (e, stackTrace) {
if (shouldLog) {
NyLogger.error('[$providerName] boot failed: $e');
NyLogger.error(stackTrace.toString());
}
if (throwOnError) rethrow;
}
}
Backpack.instance.save(key, nylo);
if (nylo.shouldMonitorAppUsage()) {
await Nylo.appLaunched();
}
return nylo;
}