We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
// eventbus\nats\consumer.go func (c *consumer) addHandler(handler eventbus.EventHandler) int { pointer := reflect.ValueOf(handler).Pointer() c.rw.Lock() defer c.rw.Unlock() c.handlers[pointer] = handler return len(c.handlers) }
// eventbus\nats\consumer.go pointer := reflect.ValueOf(handler).Pointer() // pointer总是返回同一个值
pointer总是返回同一个值 这将导致:同一个 topic,注册两个处理函数,后注册的会顶掉先注册的。
// 添加处理器 func (c *consumer) addHandler(handler eventbus.EventHandler) int { pointer := reflect.ValueOf(handler).Pointer() c.rw.Lock() defer c.rw.Unlock() if _, ok := c.handlers[pointer]; !ok { c.handlers[pointer] = make([]eventbus.EventHandler, 0, 1) } c.handlers[pointer] = append(c.handlers[pointer], handler) return len(c.handlers[pointer]) }
// eventbus\nats\consumer.go func (c *consumer) addHandler(handler eventbus.EventHandler) int { // pointer := reflect.ValueOf(handler).Pointer() pointer := reflect.ValueOf(unsafe.Pointer(&handler)).Pointer() c.rw.Lock() defer c.rw.Unlock() c.handlers[pointer] = handler return len(c.handlers) }
The text was updated successfully, but these errors were encountered:
感谢你提出的问题和解决方案。v2版本的初衷确实是为了一个事件同时被多个订阅函数进行处理。当时还考虑到取消订阅的API,因而采用了slice的的方案来存入多个函数。但目前的取消订阅的API会出现一个取消全部都取消的问题,因此后续会对该API进行优化,到时候会采用你的方案来进行处理。
Sorry, something went wrong.
No branches or pull requests
我目前使用的V1版本,代码如下:
经调试发现:
问题:
pointer总是返回同一个值
这将导致:同一个 topic,注册两个处理函数,后注册的会顶掉先注册的。
于是,我在V2发现了这个变动, 代码如下:
疑问点:
The text was updated successfully, but these errors were encountered: