gookit / event

📢 Lightweight event manager and dispatcher implements by Go. Go实现的轻量级的事件管理、调度程序库, 支持设置监听器的优先级, 支持使用通配符来进行一组事件的监听
https://pgk.go.dev/github.com/gookit/event
MIT License
513 stars 59 forks source link

goroutine并发添加event时候提示fatal error: concurrent map writes #60

Closed TaixiangLu closed 8 months ago

TaixiangLu commented 9 months ago

demo e := &MyEvent{customData: "hello"} e.SetName("e1") event.AddEvent(e) 这里提示 fatal error: concurrent map writes 原因是 event.AddEvent方法里线程不安全的操作了map,这里为何不加上锁做成线程安全的呢?

jiftle commented 9 months ago

me too

inhere commented 9 months ago

AddEvent 是用于注册一些预定义的事件对象,这里不需要加锁呀 就跟http server注册路由一样,应该在项目启动时就注册好了。

不会运行中临时添加,这种临时添加的没必要注册为event了(临时添加 说明信息一直在变化,注册上去浪费且没意义了),直接使用临时参数触发事件就行。

jiftle commented 6 months ago

啥也不是,都报错了。至少不健壮吧

inhere commented 6 months ago

v1.1.2 开始 addEvent 已经加锁了。