I am using google pubsub to publish a lot of records which is happening concurrently, but after few dozens of publishes, I get an error : concurrent map write.
I have read that I am suppose to use sync.Map{} or sync.Mutex, but I haven't found an example that helped me understand how to use it in my specific situation.
Here is a code snippet that causes me problems:
md := metadata.Collect(ctx)
records, err := s.emailRepository.SetCurrentVersionWithEnsure(ctx, md.GetTransactionId(), valid)
if err != nil {
return err
}
for _, value := range records {
go s.pub.PublishAction(md, value)
}
return nil
Variable records is of type map[string][]byte
If anyone can help with this, I would be grateful. Cheers !