Publish executes callback defined for a topic. Any additional argument will be transferred to the callback.
(topic string, args ...interface{})
| 147 | |
| 148 | // Publish executes callback defined for a topic. Any additional argument will be transferred to the callback. |
| 149 | func (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 | |
| 174 | func (bus *ChainBus) doPublish(handler *eventHandler, topic string, args ...interface{}) { |
| 175 | passedArguments := bus.setUpPublish(topic, args...) |
nothing calls this directly
no test coverage detected