Skip to content

Commit

Permalink
fix: return the first response when broadcasting to a single socket
Browse files Browse the repository at this point in the history
  • Loading branch information
zishang520 committed Feb 6, 2024
1 parent 41328e1 commit 2e86462
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion socket/broadcast-operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (b *BroadcastOperator) Emit(ev string, args ...any) error {
if 0 == atomic.LoadUint32(&timedOut) && expectedServerCount == atomic.LoadInt64(&actualServerCount) && uint64(len(responses)) == atomic.LoadUint64(&expectedClientCount) {
utils.ClearTimeout(timer)
if b.flags.ExpectSingleResponse {
ack(nil, nil)
ack(responses[0], nil)

Check failure on line 235 in socket/broadcast-operator.go

View workflow job for this annotation

GitHub Actions / build

cannot use responses[0] (variable of type any) as []any value in argument to ack: need type assertion
} else {
ack(responses, nil)
}
Expand Down
4 changes: 4 additions & 0 deletions socket/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,12 +430,16 @@ func (n *Namespace) EmitWithAck(ev string, args ...any) func(func([]any, error))
// // this is equivalent to
// myNamespace.Emit("message", "hello")
func (n *Namespace) Send(args ...any) NamespaceInterface {
// This type-cast is needed because EmitEvents likely doesn't have `message` as a key.
// if you specify the EmitEvents, the type of args will be never.
n.Emit("message", args...)
return n
}

// Sends a `message` event to all clients. Sends a `message` event. Alias of [Send].
func (n *Namespace) Write(args ...any) NamespaceInterface {
// This type-cast is needed because EmitEvents likely doesn't have `message` as a key.
// if you specify the EmitEvents, the type of args will be never.
n.Emit("message", args...)
return n
}
Expand Down
4 changes: 4 additions & 0 deletions socket/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -684,12 +684,16 @@ func (s *Server) EmitWithAck(ev string, args ...any) func(func([]any, error)) {
// // this is equivalent to
// io.Emit("message", "hello")
func (s *Server) Send(args ...any) *Server {
// This type-cast is needed because EmitEvents likely doesn't have `message` as a key.
// if you specify the EmitEvents, the type of args will be never.
s.sockets.Emit("message", args...)
return s
}

// Sends a `message` event to all clients. Alias of [Send].
func (s *Server) Write(args ...any) *Server {
// This type-cast is needed because EmitEvents likely doesn't have `message` as a key.
// if you specify the EmitEvents, the type of args will be never.
s.sockets.Emit("message", args...)
return s
}
Expand Down

0 comments on commit 2e86462

Please sign in to comment.