other: 优化
This commit is contained in:
parent
409350f530
commit
64c165317b
|
@ -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]) {
|
go func(r *Reactor[M], q *queue.Queue[int, string, M]) {
|
||||||
defer r.wg.Done()
|
defer r.wg.Done()
|
||||||
for m := range q.Read() {
|
for m := range q.Read() {
|
||||||
m(r.process, func(m queue.MessageWrapper[int, string, M], last bool) {
|
m(r.process, r.processFinish)
|
||||||
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()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}(r, q)
|
}(r, q)
|
||||||
}
|
}
|
||||||
|
@ -212,3 +194,23 @@ func (r *Reactor[M]) Close() {
|
||||||
atomic.StoreInt32(&r.state, statusClosed)
|
atomic.StoreInt32(&r.state, statusClosed)
|
||||||
r.queueRW.Unlock()
|
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()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue