MCPcopy Create free account
hub / github.com/asaskevich/EventBus / Register

Method Register

server.go:132–153  ·  view source on GitHub ↗

Register - Registers a remote handler to this event bus for a remote subscribe - a given client address only needs to subscribe once event will be republished in local event bus

(arg *SubscribeArg, success *bool)

Source from the content-addressed store, hash-verified

130// for a remote subscribe - a given client address only needs to subscribe once
131// event will be republished in local event bus
132func (service *ServerService) Register(arg *SubscribeArg, success *bool) error {
133 subscribers := service.server.subscribers
134 if !service.server.HasClientSubscribed(arg) {
135 rpcCallback := service.server.rpcCallback(arg)
136 switch arg.SubscribeType {
137 case Subscribe:
138 service.server.eventBus.Subscribe(arg.Topic, rpcCallback)
139 case SubscribeOnce:
140 service.server.eventBus.SubscribeOnce(arg.Topic, rpcCallback)
141 }
142 var topicSubscribers []*SubscribeArg
143 if _, ok := subscribers[arg.Topic]; ok {
144 topicSubscribers = []*SubscribeArg{arg}
145 } else {
146 topicSubscribers = subscribers[arg.Topic]
147 topicSubscribers = append(topicSubscribers, arg)
148 }
149 subscribers[arg.Topic] = topicSubscribers
150 }
151 *success = true
152 return nil
153}

Callers 3

StartMethod · 0.80
TestRegisterFunction · 0.80
StartMethod · 0.80

Calls 4

HasClientSubscribedMethod · 0.80
rpcCallbackMethod · 0.80
SubscribeMethod · 0.65
SubscribeOnceMethod · 0.65

Tested by 1

TestRegisterFunction · 0.64