-
-
Save emretanriverdi/95557ecfad2386d1c773067a3ade71df to your computer and use it in GitHub Desktop.
concurrent-map-wrong.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func getContentDetails(contentIds []int) { | |
var wg sync.WaitGroup | |
var result = make(map[int][]Content, len(contentIds)) | |
wg.Add(len(contentIds)) | |
for _, contentId := range contentIds { | |
go func(result map[int][]Content, contentId int, | |
wg *sync.WaitGroup) { | |
defer wg.Done() | |
content := service.GetContent(contentId) | |
result[contentId] = content | |
fmt.Println("Done!") | |
}(result, contentId, &wg) | |
} | |
wg.Wait() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment