1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-12-22 23:35:46 +01:00

Implement ranging over groups.

This commit is contained in:
Juliusz Chroboczek 2020-09-13 12:24:06 +02:00
parent fb02c6fe1f
commit 22c6ad6b8c
2 changed files with 21 additions and 12 deletions

View file

@ -123,14 +123,25 @@ func addGroup(name string, desc *groupDescription) (*group, error) {
return g, nil
}
func getGroupNames() []string {
func rangeGroups(f func(g *group) bool) {
groups.mu.Lock()
defer groups.mu.Unlock()
names := make([]string, 0, len(groups.groups))
for name := range groups.groups {
names = append(names, name)
for _, g := range groups.groups {
ok := f(g)
if !ok {
break
}
}
}
func getGroupNames() []string {
names := make([]string, 0)
rangeGroups(func(g *group) bool {
names = append(names, g.name)
return true
})
return names
}
@ -408,16 +419,15 @@ type publicGroup struct {
func getPublicGroups() []publicGroup {
gs := make([]publicGroup, 0)
groups.mu.Lock()
defer groups.mu.Unlock()
for _, g := range groups.groups {
rangeGroups(func (g *group) bool {
if g.description.Public {
gs = append(gs, publicGroup{
Name: g.name,
ClientCount: len(g.clients),
})
}
}
return true
})
sort.Slice(gs, func(i, j int) bool {
return gs[i].Name < gs[j].Name
})

View file

@ -47,11 +47,10 @@ func webserver() {
IdleTimeout: 120 * time.Second,
}
server.RegisterOnShutdown(func() {
groups.mu.Lock()
defer groups.mu.Unlock()
for _, g := range groups.groups {
rangeGroups(func (g *group) bool {
go g.shutdown("server is shutting down")
}
return true
})
})
go func() {
var err error