run method
Runs the application.
All services will be initialized in the order they are supplied.
When catchSignal
is true and termination is requested by CTRL+C or
as soon as cancel
is triggered, all services will be shut down and
this future will complete.
Implementation
Future<void> run([CancellationToken? cancel]) async {
final stopwatch = Stopwatch()..start();
try {
await initialize();
} catch (e) {
await shutdown();
exit(0);
}
ProcessSignal.sigint.watch().listen((signal) {
if (isInShutdown) {
exit(0);
} else {
shutdown();
}
});
cancel?.attach(shutdown);
stopwatch.stop();
final configService = resolveService<ConfigService?>();
if (configService != null) {
resolveService<LogService?>()?.info(
'Initialized ${configService.serviceName} in ${stopwatch.elapsed}.',
sender: 'DataHub',
);
} else {
resolveService<LogService?>()?.info(
'Initialisation done in ${stopwatch.elapsed}.',
sender: 'DataHub',
);
}
onInitialized?.call();
await _runTimeCompleter.future;
exit(0);
}