diff --git a/main.go b/main.go index 02eb6e5..53733e5 100644 --- a/main.go +++ b/main.go @@ -168,6 +168,7 @@ func broadcastFiber(name string) { e := ctx.clientsChanList.Front() for e != nil { ch := e.Value.(*ClientChannel) + // Note: select in Golang is not ordered! select { case <-ch.Notify: // Closed client, remove this entry @@ -175,11 +176,14 @@ func broadcastFiber(name string) { next := e.Next() ctx.clientsChanList.Remove(e) e = next - case ch.Data <- chunk: - e = e.Next() + break default: - e = e.Next() } + select { + case ch.Data <- chunk: + default: + } + e = e.Next() } // Try to serve all new clients, but don't get locked up here :) if ctx.newClientsChanList.Len() > 0 && ctx.newChanLock.TryLock() {