avoid concurrent map iteration and map write

This commit is contained in:
aoife cassidy 2025-11-01 21:40:57 +01:00
parent a2ffa6b706
commit 51e55d2428
No known key found for this signature in database
GPG Key ID: 7184AC1C9835CE48

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"log" "log"
"maps"
"net" "net"
"os" "os"
"slices" "slices"
@ -214,12 +215,7 @@ func (m model) View() (s string) {
} }
s += fmt.Sprintf("%d user%s connected:\n", numUsers, plural) s += fmt.Sprintf("%d user%s connected:\n", numUsers, plural)
keys := make([]string, 0, numUsers) for _, nick := range slices.Sorted(maps.Keys(m.users)) {
for k := range m.users {
keys = append(keys, k)
}
slices.Sort(keys)
for _, nick := range keys {
user := m.users[nick] user := m.users[nick]
status := " " status := " "
nickStyled := styleInactive.Render(nick) nickStyled := styleInactive.Render(nick)