registerHook method
Implementation
void registerHook(ShutdownHook hook) {
if (_isShuttingDown || _isShutdown) {
throw StateError('Cannot register hooks during shutdown');
}
_hooks[hook.phase]!.add(hook);
_hooks[hook.phase]!.sort((a, b) => b.critical ? 1 : -1);
}