An in-memory fan-out server in Go: accept many client connections, take work items on an input queue, and dispatch each item to every connection through a bounded worker pool — all coordinated over channels, no locks on the hot path.
In(packet) ─► works channel ─► dispatch loop ─► idle worker ─► every connection.Channel
- Server (
pkg/server) — owns theworksqueue, the worker slice, and the connection registry.Subscribe/Unsubscriberegister connections (mutex-guarded);Inwraps a packet as aWorkwith a UUID and enqueues it. The dispatch loop pulls a work item, waits for a worker to advertise itself onworkerChannel, and hands the item over. - Worker (
internal/worker) — each worker loops: publish its own channel toworkerChannel, receive aWork, then push it to every current connection's channel. Worker count is fixed at construction and bounds concurrency. - Connectors (
pkg/connection) — slice of connections; unsubscribe is O(n) swap-delete (order doesn't matter). - Sizing: fewer workers for CPU-bound packets, more for I/O-bound.
s := server.NewServer(/* workerSize */ 4, /* workQueueSize */ 128)
s.Start()
c := s.Subscribe()
go func() { for w := range c.Channel { /* send w.Data to the client */ } }()
s.In("hello")
s.Status() // { Connections, WorkerSize, WorkQueueSize, Works }
s.Stop()go test ./...Go 1.13 · google/uuid. Covered by server and connection tests.
Built 2020 to work through channel-based fan-out and worker-pool patterns in Go. Not maintained.