Skip to content

Commit 1c65b49

Browse files
stemlaudMarcoPolo
authored andcommitted
refactor: use reflect.TypeFor
Signed-off-by: stemlaud <[email protected]>
1 parent 3f09fa4 commit 1c65b49

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

p2p/host/eventbus/basic.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func (w *wildcardSub) Close() error {
133133
w.closeOnce.Do(func() {
134134
w.w.removeSink(w.ch)
135135
if w.metricsTracer != nil {
136-
w.metricsTracer.RemoveSubscriber(reflect.TypeOf(event.WildcardSubscription))
136+
w.metricsTracer.RemoveSubscriber(reflect.TypeFor[*event.wildcardSubscriptionType]())
137137
}
138138
})
139139

@@ -345,7 +345,7 @@ func (n *wildcardNode) addSink(sink *namedSink) {
345345
n.Unlock()
346346

347347
if n.metricsTracer != nil {
348-
n.metricsTracer.AddSubscriber(reflect.TypeOf(event.WildcardSubscription))
348+
n.metricsTracer.AddSubscriber(reflect.TypeFor[*event.wildcardSubscriptionType]())
349349
}
350350
}
351351

@@ -368,7 +368,7 @@ func (n *wildcardNode) removeSink(ch chan interface{}) {
368368
n.Unlock()
369369
}
370370

371-
var wildcardType = reflect.TypeOf(event.WildcardSubscription)
371+
var wildcardType = reflect.TypeFor[*event.wildcardSubscriptionType]()
372372

373373
func (n *wildcardNode) emit(evt interface{}) {
374374
if n.nSinks.Load() == 0 {

p2p/host/eventbus/basic_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,15 @@ func TestGetAllEventTypes(t *testing.T) {
113113

114114
evts := bus.GetAllEventTypes()
115115
require.Len(t, evts, 1)
116-
require.Equal(t, reflect.TypeOf((*EventB)(nil)).Elem(), evts[0])
116+
require.Equal(t, reflect.TypeFor[EventB](), evts[0])
117117

118118
_, err = bus.Emitter(new(EventA))
119119
require.NoError(t, err)
120120

121121
evts = bus.GetAllEventTypes()
122122
require.Len(t, evts, 2)
123-
require.Contains(t, evts, reflect.TypeOf((*EventB)(nil)).Elem())
124-
require.Contains(t, evts, reflect.TypeOf((*EventA)(nil)).Elem())
123+
require.Contains(t, evts, reflect.TypeFor[EventB]())
124+
require.Contains(t, evts, reflect.TypeFor[EventA]())
125125
}
126126

127127
func TestEmitNoSubNoBlock(t *testing.T) {

0 commit comments

Comments
 (0)