Files
toutoukan/goroutine/consumer.go
2025-08-13 07:11:17 +08:00

28 lines
647 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package goroutine
import (
"fmt"
"sync"
"toutoukan/model/routine"
)
func NewConsumer(ch chan routine.Task, wg *sync.WaitGroup, done chan struct{}, num int, data *routine.Data, rwmutex *sync.RWMutex) {
defer wg.Done()
for {
select {
case <-ch:
rwmutex.RLock()
fmt.Printf("消费者%d号处理消息统计消息总数为%d\n", num+1, data.Count)
fmt.Printf("消费者%d号当前记录详情如下\n", num+1)
for key, value := range data.Record {
fmt.Printf(" 键:%d%d\n", key, value)
}
rwmutex.RUnlock()
case <-done:
fmt.Printf("消费者%d号退出接收\n", num+1)
return
}
}
}