aceld / aceld/zinx

RouterSlices中Handlers的意义还存在逻辑错误

Aperta
#291 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Go
Stelle
7.8k
Fork
1.3k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

```ruby
func (r *RouterSlices) AddHandler(msgId uint32, Handlers ...ziface.RouterHandler) {
// 1. Check if the API handler method bound to the current msg already exists
if _, ok := r.Apis[msgId]; ok {
panic("repeated api , msgId = " + strconv.Itoa(int(msgId)))
}

finalSize := len(r.Handlers) + len(Handlers)
mergedHandlers := make([]ziface.RouterHandler, finalSize)
copy(mergedHandlers, r.Handlers)
copy(mergedHandlers[len(r.Handlers):], Handlers)
r.Apis[msgId] = append(r.Apis[msgId], mergedHandlers...)
}
```

```ruby
type RouterSlices struct {
Apis map[uint32][]ziface.RouterHandler
Handlers []ziface.RouterHandler
sync.RWMutex
}
```

我不理解这个结构体中Handlers的意义,我的理解应该是每一个msgid有一个自己的handler切片,但是可以添加handler,为什么要判断当前msgid是否在map中存在,此外为什么新的msgID需要加上原来的r.Handlers,还有是不是需要加一个写锁,防止并发安全的问题,望解答!!!

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.