Skip to content

Conversation

@MarcoPolo
Copy link
Contributor

topic.Publish is already thread safe. topic.AddToBatch should strive to follow similar semantics.

Looking at how this would integrate with Prysm, they use separate goroutines per message they'd like to batch.

messagebatch.go Outdated
Comment on lines 18 to 30
func (mb *MessageBatch) addMessage(msg *Message) {
mb.mu.Lock()
defer mb.mu.Unlock()
mb.messages = append(mb.messages, msg)
}

func (mb *MessageBatch) takeMessages() []*Message {
mb.mu.Lock()
defer mb.mu.Unlock()
messages := mb.messages
mb.messages = nil
return messages
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: I prefer just add and take

@MarcoPolo MarcoPolo force-pushed the marco/batch-publish-thread-safe branch from 24139da to bf93aab Compare June 25, 2025 19:05
@MarcoPolo MarcoPolo merged commit fedbccc into master Jun 25, 2025
9 checks passed
@MarcoPolo MarcoPolo deleted the marco/batch-publish-thread-safe branch June 25, 2025 19:38
@MarcoPolo MarcoPolo mentioned this pull request Jun 25, 2025
MarcoPolo added a commit that referenced this pull request Jun 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants