public async Task Shutdown() { Emit("ShuttingDown", true); _isReady = false; Router.Stop(); // Cleanup script file watcher if (_watchSubscription != null) { _watchSubscription.Dispose(); } _scriptRunner.Cleanup(); Listeners.Clear(); foreach (var adapter in _adapters.Values) { await adapter.Close(); } if (_brain != null) { await _brain.Close(); } Emit("ShutdownComplete", true); }