MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / Publish

Method Publish

chainbus/bus.go:149–172  ·  view source on GitHub ↗

Publish executes callback defined for a topic. Any additional argument will be transferred to the callback.

(topic string, args ...interface{})

Source from the content-addressed store, hash-verified

147
148// Publish executes callback defined for a topic. Any additional argument will be transferred to the callback.
149func (bus *ChainBus) Publish(topic string, args ...interface{}) {
150 bus.lock.Lock() // will unlock if handler is not found or always after setUpPublish
151 defer bus.lock.Unlock()
152 if handlers, ok := bus.handlers[topic]; ok && 0 < len(handlers) {
153 // Handlers slice may be changed by removeHandler and Unsubscribe during iteration,
154 // so make a copy and iterate the copied slice.
155 copyHandlers := make([]*eventHandler, 0, len(handlers))
156 copyHandlers = append(copyHandlers, handlers...)
157 for i, handler := range copyHandlers {
158 if handler.flagOnce {
159 bus.removeHandler(topic, i)
160 }
161 if !handler.async {
162 bus.doPublish(handler, topic, args...)
163 } else {
164 bus.wg.Add(1)
165 if handler.transactional {
166 handler.Lock()
167 }
168 go bus.doPublishAsync(handler, topic, args...)
169 }
170 }
171 }
172}
173
174func (bus *ChainBus) doPublish(handler *eventHandler, topic string, args ...interface{}) {
175 passedArguments := bus.setUpPublish(topic, args...)

Callers

nothing calls this directly

Calls 4

removeHandlerMethod · 0.95
doPublishMethod · 0.95
doPublishAsyncMethod · 0.95
AddMethod · 0.45

Tested by

no test coverage detected