util/eventbus: make internal queue a generic type

In preparation for making the queues carry additional event metadata.

Updates #15160

Signed-off-by: David Anderson <dave@tailscale.com>
This commit is contained in:
David Anderson
2025-03-05 10:33:35 -08:00
committed by Dave Anderson
parent 96202a7c0c
commit bf40bc4fa0
3 changed files with 18 additions and 16 deletions

View File

@@ -27,7 +27,7 @@ type subscriber interface {
// processing other potential sources of wakeups, which is how we end
// up at this awkward type signature and sharing of internal state
// through dispatch.
dispatch(ctx context.Context, vals *queue, acceptCh func() chan any) bool
dispatch(ctx context.Context, vals *queue[any], acceptCh func() chan any) bool
Close()
}
@@ -55,7 +55,7 @@ func newSubscribeState(c *Client) *subscribeState {
}
func (q *subscribeState) pump(ctx context.Context) {
var vals queue
var vals queue[any]
acceptCh := func() chan any {
if vals.Full() {
return nil
@@ -155,7 +155,7 @@ func (s *Subscriber[T]) subscribeType() reflect.Type {
return reflect.TypeFor[T]()
}
func (s *Subscriber[T]) dispatch(ctx context.Context, vals *queue, acceptCh func() chan any) bool {
func (s *Subscriber[T]) dispatch(ctx context.Context, vals *queue[any], acceptCh func() chan any) bool {
t := vals.Peek().(T)
for {
// Keep the cases in this select in sync with subscribeState.pump