start method
Starts the Serverpod and all Servers that it manages.
If runInGuardedZone is set to true (the default),
the start function will be executed inside runZonedGuarded.
Any errors during the start up sequence will cause the process to exit.
Any runtime errors will be in their own error zone and will not crash the server.
If runInGuardedZone is set to false, the start function will be executed in the same error zone as the caller.
An ExitException will be thrown if the start up sequence fails.
Implementation
Future<void> start({bool runInGuardedZone = true}) async {
_startedTime = DateTime.now().toUtc();
void onZoneError(Object error, StackTrace stackTrace) {
if (error is ExitException) {
if (error.message != '') {
stderr.writeln(error.message);
}
exit(error.exitCode);
}
_exitCode = 1;
_reportException(
error,
stackTrace,
message: 'Internal server error. Zoned exception.',
);
}
if (runInGuardedZone) {
await runZonedGuarded(() async {
await _unguardedStart();
}, onZoneError);
} else {
await _unguardedStart();
if (_exitCode != 0) {
throw ExitException(_exitCode);
}
}
}