util/eventbus: remove redundant code from eventbus.Publish

eventbus.Publish() calls newPublisher(), which in turn invokes (*Client).addPublisher().
That method adds the new publisher to c.pub, so we don’t need to add it again in eventbus.Publish.

Updates #cleanup

Signed-off-by: Nick Khyl <nickk@tailscale.com>
This commit is contained in:
Nick Khyl
2025-06-13 18:08:22 -05:00
committed by Nick Khyl
parent 5b7cf7fc36
commit 866614202c
3 changed files with 13 additions and 20 deletions

View File

@@ -113,15 +113,16 @@ func (c *Client) shouldPublish(t reflect.Type) bool {
// Subscribe requests delivery of events of type T through the given
// Queue. Panics if the queue already has a subscriber for T.
func Subscribe[T any](c *Client) *Subscriber[T] {
return newSubscriber[T](c.subscribeState())
r := c.subscribeState()
s := newSubscriber[T](r)
r.addSubscriber(s)
return s
}
// Publisher returns a publisher for event type T using the given
// client.
func Publish[T any](c *Client) *Publisher[T] {
ret := newPublisher[T](c)
c.mu.Lock()
defer c.mu.Unlock()
c.pub.Add(ret)
return ret
p := newPublisher[T](c)
c.addPublisher(p)
return p
}