feat: WebSocket upgrader, hub, send, broadcast, handler con tests (issue 0011 fase 3-4)
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
package infra
|
||||
|
||||
import "fmt"
|
||||
|
||||
// WSSend envia bytes al canal Send de un cliente especifico de forma no bloqueante.
|
||||
// Si el canal esta lleno o el cliente desconectado, retorna error sin bloquear al emisor.
|
||||
// Para broadcast a todos los clientes usar WSBroadcast.
|
||||
func WSSend(client *WSClient, msg []byte) error {
|
||||
if client == nil {
|
||||
return fmt.Errorf("ws send: client is nil")
|
||||
}
|
||||
select {
|
||||
case client.Send <- msg:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("ws send: client %s send channel full or closed", client.ID)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user