From c860fb96a3c9fec2caed91a89dda56987f183197 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Sat, 11 Sep 2021 15:42:14 +0200 Subject: [PATCH] Move server shutdown into group.go. --- group/group.go | 8 ++++++-- webserver/webserver.go | 5 +---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/group/group.go b/group/group.go index 82e6c39..2e8b31c 100644 --- a/group/group.go +++ b/group/group.go @@ -701,8 +701,12 @@ func kickall(g *Group, message string) { }) } -func (g *Group) Shutdown(message string) { - kickall(g, message) +func Shutdown(message string) { + Range(func(g *Group) bool { + g.SetLocked(true, message) + kickall(g, message) + return true + }) } type warner interface { diff --git a/webserver/webserver.go b/webserver/webserver.go index 3fdffce..e43a79a 100644 --- a/webserver/webserver.go +++ b/webserver/webserver.go @@ -70,10 +70,7 @@ func Serve(address string, dataDir string) error { } } s.RegisterOnShutdown(func() { - group.Range(func(g *group.Group) bool { - go g.Shutdown("server is shutting down") - return true - }) + group.Shutdown("server is shutting down") }) server.Store(s)