Skip to content

Commit afdb01d

Browse files
committed
feat: add context parameter to Publish method for better cancellation control
1 parent 265d222 commit afdb01d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ func (c *Client) Subscribe(topic string) <-chan Message {
244244
}
245245

246246
// Publish publishes a message to the specified topic.
247-
func (c *Client) Publish(topic string, data []byte) error {
247+
func (c *Client) Publish(ctx context.Context, topic string, data []byte) error {
248248
t, ok := c.topics[topic]
249249
if !ok {
250250
var err error
@@ -269,7 +269,7 @@ func (c *Client) Publish(topic string, data []byte) error {
269269
return fmt.Errorf("failed to marshal message: %w", err)
270270
}
271271

272-
return t.Publish(c.ctx, msgBytes)
272+
return t.Publish(ctx, msgBytes)
273273
}
274274

275275
// GetPeers returns information about all known peers on subscribed topics.

0 commit comments

Comments
 (0)