Update
This commit is contained in:
1 parent
3530afb854
commit
6903fcff27
2146 files changed
+112256
-190703
No files matched your search
+16
-4
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// Copyright (c) Tailscale Inc & contributors
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
package eventbus
|
||||
@@ -146,7 +146,10 @@ func Subscribe[T any](c *Client) *Subscriber[T] {
|
||||
|
||||
r := c.subscribeStateLocked()
|
||||
s := newSubscriber[T](r, logfForCaller(c.logger()))
|
||||
r.addSubscriber(s)
|
||||
// Register the non-generic core with the bus rather than the typed facade,
|
||||
// mirroring SubscribeFunc and Publish: this keeps the bus's outputs map
|
||||
// and subscriber-interface itab out of per-T cost.
|
||||
r.addSubscriber(s.core)
|
||||
return s
|
||||
}
|
||||
|
||||
@@ -169,7 +172,11 @@ func SubscribeFunc[T any](c *Client, f func(T)) *SubscriberFunc[T] {
|
||||
|
||||
r := c.subscribeStateLocked()
|
||||
s := newSubscriberFunc[T](r, f, logfForCaller(c.logger()))
|
||||
r.addSubscriber(s)
|
||||
// Register the non-generic core, not the typed facade. Doing
|
||||
// so means the bus's outputs map and the subscriber interface
|
||||
// itab are not parameterized by T, eliminating per-T itab and
|
||||
// dictionary cost.
|
||||
r.addSubscriber(s.core)
|
||||
return s
|
||||
}
|
||||
|
||||
@@ -177,6 +184,11 @@ func SubscribeFunc[T any](c *Client, f func(T)) *SubscriberFunc[T] {
|
||||
// It panics if c is closed.
|
||||
func Publish[T any](c *Client) *Publisher[T] {
|
||||
p := newPublisher[T](c)
|
||||
c.addPublisher(p)
|
||||
// Register the non-generic core with the client so the
|
||||
// per-Client publisher set, the publisher interface itab, and
|
||||
// the publisher equality function are not parameterized by T.
|
||||
// This eliminates per-T itab/dictionary/eq cost for every new
|
||||
// event type passed through Publish[T].
|
||||
c.addPublisher(p.core)
|
||||
return p
|
||||
}
|
||||
Reference in new issue
Block a user