Skip to content

Commit

Permalink
优化初始化channel
Browse files Browse the repository at this point in the history
  • Loading branch information
steden committed Jul 8, 2024
1 parent 1cd3d23 commit 5085de3
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions rabbitProduct.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,9 @@ func (receiver *rabbitProduct) popChannel() rabbitChannel {
receiver.init()
}

timer := time.NewTimer(10 * time.Millisecond)
for {
timer.Reset(10 * time.Millisecond)
select {
case <-timer.C:
case <-time.NewTimer(10 * time.Millisecond).C:
if receiver.workChannelCount >= receiver.manager.config.MaxChannel {
continue
}
Expand All @@ -78,11 +76,13 @@ func (receiver *rabbitProduct) init() {
receiver.workChannelCount = 0
receiver.chlQueue = make(chan rabbitChannel, 2048)
// 按最低channel要求,创建指定数量的channel
for len(receiver.chlQueue) < receiver.manager.config.MinChannel {
if channel := receiver.createChannelAndConfirm(); channel.chl != nil && !channel.chl.IsClosed() {
receiver.chlQueue <- channel
go func() {
for len(receiver.chlQueue) < receiver.manager.config.MinChannel {
if channel := receiver.createChannelAndConfirm(); channel.chl != nil && !channel.chl.IsClosed() {
receiver.chlQueue <- channel
}
}
}
}()
}

// 创建通道
Expand Down

0 comments on commit 5085de3

Please sign in to comment.