Files
fn_registry/functions/infra/ws_send.md
T
egutierrez 47fac22230 chore: auto-commit (799 archivos)
- .claude/CLAUDE.md
- .claude/commands/subagentes.md
- .claude/rules/INDEX.md
- .mcp.json
- bash/functions/cybersecurity/analyze_dns.md
- bash/functions/cybersecurity/audit_http_headers.md
- bash/functions/cybersecurity/audit_ssh_config.md
- bash/functions/cybersecurity/check_firewall.md
- bash/functions/cybersecurity/detect_suspicious_users.md
- bash/functions/cybersecurity/encrypt_file.md
- ...

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-14 00:28:20 +02:00

1.8 KiB

name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, params, output, tested, tests, test_file_path, file_path
name kind lang domain version purity signature description tags uses_functions uses_types returns returns_optional error_type imports params output tested tests test_file_path file_path
ws_send function go infra 1.0.0 impure func WSSend(client *WSClient, msg []byte) error Envia bytes al canal Send de un cliente WebSocket 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 del hub usar WSBroadcast en su lugar.
websocket
send
server
infra
realtime
pendiente-usar
WSClient_go_infra
false error_go_core
fmt
name desc
client *WSClient destinatario. Si es nil retorna error.
name desc
msg bytes a enviar. Tipicamente JSON serializado de un WSMessage. Se entregan tal cual al websocket.Conn.
error si el canal Send esta lleno (cliente lento) o cerrado (cliente desconectado). Nil si el mensaje se encolo correctamente. true
envia mensaje al canal Send del cliente
retorna error si client es nil
retorna error si el canal esta lleno
functions/infra/ws_test.go functions/infra/ws_send.go

Ejemplo

// Enviar mensaje a un cliente especifico (unicast)
target := findClientByID(hub, "user-42")
err := WSSend(target, []byte(`{"type":"notification","text":"hola"}`))
if err != nil {
    log.Printf("send failed: %v", err)
}

Notas

Funcion no bloqueante: si el cliente no consume su canal Send, este se llena y la funcion retorna error inmediatamente en vez de bloquear al emisor. Esto previene que un cliente lento bloquee a otros productores.

El mensaje se encola en client.Send — la goroutine writePump del cliente lo escribira al websocket.Conn. No hay garantia de orden estricto entre llamadas concurrentes a WSSend sobre el mismo cliente.