PR feedback: name change and account for different options order
This commit is contained in:
parent
7981f9bfbd
commit
6bd07a71fc
|
@ -76,7 +76,7 @@ func (gs *GossipSubRouter) Attach(p *PubSub) {
|
|||
gs.p = p
|
||||
gs.tracer = p.tracer
|
||||
// start using the same msg ID function as PubSub for caching messages.
|
||||
gs.mcache.ChangeMsgIdFn(p.msgID)
|
||||
gs.mcache.SetMsgIdFn(p.msgID)
|
||||
go gs.heartbeatTimer()
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ type MessageCache struct {
|
|||
msgID MsgIdFunction
|
||||
}
|
||||
|
||||
func (mc *MessageCache) ChangeMsgIdFn(msgID MsgIdFunction) {
|
||||
func (mc *MessageCache) SetMsgIdFn(msgID MsgIdFunction) {
|
||||
mc.msgID = msgID
|
||||
}
|
||||
|
||||
|
|
|
@ -254,6 +254,10 @@ type MsgIdFunction func(pmsg *pb.Message) string
|
|||
func WithMessageIdFn(fn MsgIdFunction) Option {
|
||||
return func(p *PubSub) error {
|
||||
p.msgID = fn
|
||||
// the tracer Option may already be set. Update its message ID function to make options order-independent.
|
||||
if p.tracer != nil {
|
||||
p.tracer.msgID = fn
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue