mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-25 20:57:31 +00:00
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:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user