19 lines
526 B
Go
19 lines
526 B
Go
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)
|
|
}
|
|
}
|