From f2be25cb50fcb268281fde82ced65b99c12c750e Mon Sep 17 00:00:00 2001 From: Fisher <905488821@qq.com> Date: Wed, 27 Sep 2023 18:24:32 +0800 Subject: [PATCH] Multiple OnceAsync functions will be executed multiple times Multiple OnceAsync functions will be executed multiple times --- event_bus.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/event_bus.go b/event_bus.go index dedc7fd..d7e7f45 100644 --- a/event_bus.go +++ b/event_bus.go @@ -136,9 +136,9 @@ func (bus *EventBus) Publish(topic string, args ...interface{}) { // so make a copy and iterate the copied slice. copyHandlers := make([]*eventHandler, len(handlers)) copy(copyHandlers, handlers) - for i, handler := range copyHandlers { + for _, handler := range copyHandlers { if handler.flagOnce { - bus.removeHandler(topic, i) + bus.removeHandler(topic, bus.findHandlerIdx(topic, reflect.ValueOf(handler))) } if !handler.async { bus.doPublish(handler, topic, args...)