Skip to content

Commit

Permalink
remove copy variable in goroutine loop
Browse files Browse the repository at this point in the history
  • Loading branch information
crossoverJie committed Nov 19, 2024
1 parent ffdc3af commit f8c1a9e
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions pulsar/consumer_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,16 +385,16 @@ func (c *consumer) internalTopicSubscribeToPartitions() error {
for partitionIdx := startPartition; partitionIdx < newNumPartitions; partitionIdx++ {
partitionTopic := partitions[partitionIdx]

go func(idx int, pt string) {
go func() {
defer wg.Done()
opts := newPartitionConsumerOpts(pt, c.consumerName, idx, c.options)
opts := newPartitionConsumerOpts(partitionTopic, c.consumerName, partitionIdx, c.options)
cons, err := newPartitionConsumer(c, c.client, opts, c.messageCh, c.dlq, c.metrics)
ch <- ConsumerError{
err: err,
partition: idx,
partition: partitionIdx,
consumer: cons,
}
}(partitionIdx, partitionTopic)
}()
}

go func() {
Expand Down Expand Up @@ -776,7 +776,6 @@ func (c *consumer) hasNext() bool {

hasNext := make(chan bool)
for _, pc := range c.consumers {
pc := pc
go func() {
defer wg.Done()
if pc.hasNext() {
Expand Down

0 comments on commit f8c1a9e

Please sign in to comment.