other: 优化

This commit is contained in:
kercylan98 2024-04-08 09:35:46 +08:00
parent 409350f530
commit 64c165317b
1 changed files with 21 additions and 19 deletions

View File

@ -176,25 +176,7 @@ func (r *Reactor[M]) runQueue(q *queue.Queue[int, string, M]) {
go func(r *Reactor[M], q *queue.Queue[int, string, M]) {
defer r.wg.Done()
for m := range q.Read() {
m(r.process, func(m queue.MessageWrapper[int, string, M], last bool) {
if last {
r.locationRW.RLock()
mq, exist := r.location[m.Ident()]
r.locationRW.RUnlock()
if exist {
r.locationRW.Lock()
defer r.locationRW.Unlock()
mq, exist = r.location[m.Ident()]
if exist {
delete(r.location, m.Ident())
r.queueRW.RLock()
mq := r.queues[mq]
r.queueRW.RUnlock()
r.logger.Load().Debug("Reactor", log.String("action", "unbind"), log.Any("ident", m.Ident()), log.Any("queue", mq.Id()))
}
}
}
})
m(r.process, r.processFinish)
}
}(r, q)
}
@ -212,3 +194,23 @@ func (r *Reactor[M]) Close() {
atomic.StoreInt32(&r.state, statusClosed)
r.queueRW.Unlock()
}
func (r *Reactor[M]) processFinish(m queue.MessageWrapper[int, string, M], last bool) {
if last {
r.locationRW.RLock()
mq, exist := r.location[m.Ident()]
r.locationRW.RUnlock()
if exist {
r.locationRW.Lock()
defer r.locationRW.Unlock()
mq, exist = r.location[m.Ident()]
if exist {
delete(r.location, m.Ident())
r.queueRW.RLock()
mq := r.queues[mq]
r.queueRW.RUnlock()
r.logger.Load().Debug("Reactor", log.String("action", "unbind"), log.Any("ident", m.Ident()), log.Any("queue", mq.Id()))
}
}
}
}